Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: william on April 02, 2018, 08:41:33 PM

Title: export undistorted photos in python
Post by: william on April 02, 2018, 08:41:33 PM
I've been trying to recreate the GUI functionality export -> undistort photos using the Python API.

This is what I came up with, for a multiplane (MicaSense RedEdge) camera:

Code: [Select]
    for camera in chunk.cameras:
        for plane in camera.planes:
            img = plane.image()
            calib = plane.sensor.calibration
            # This is the key line for colour correction. Here, I opted not to square pixels or center principal point.
            imgu = img.undistort(calib, False, False)
            name = os.path.basename(plane.photo.path)
            imgu.save(os.path.join('undistorted/', name))

It seems to work. Unfortunately, it seems that the exif information, such as 'XMP:CaptureId' is not saved. (This is crucial for me.) Does anyone know if this can be accomplished?

EDIT: I noticed that photo.imageMeta() exists, and I also know how to extract metadata from the original photo using e.g. exiftool. But I'm not sure how to save the metadata properly to a new image.

EDIT 2: I am managing with a workaround--just using the metadata from the original images, and matching that to the undistorted images.