6
« on: May 13, 2020, 11:08:20 AM »
Hello,
I am trying to automate the processing of a set of terrestrial images using the Python API. Typically, the workflow in the GUI consisted in:
1. Importing the pictures ('Add Photos')
2. Importing a reference containing the approximate camera positions and orientations ('Import reference' -> CSV file)
3. Setting the camera pixel size + focal length and keeping intrinsic parameters to fixed values ('Tools' / 'Camera calibration')
4. Selecting the orientations in the reference pane, to allow the reference estimates to be used
5. Aligning the cameras ('Align Photos')
I think I am able to run 1, 2 and 3 correctly in the Python API:
doc = Metashape.Document()
# Create chunk
chunk = doc.addChunk()
# Find pictures in folder
ImageFiles = glob.glob('./000-175-*.tif')
ImageFiles.sort()
# Add pictures to project
for fileName in ImageFiles:
chunk.addPhotos([fileName])
sensor = chunk.sensors[0]
sensor.pixel_height = 0.021
sensor.pixel_width = 0.021
sensor.focal_length = 161
sensor.fixed_location = False
sensor.fixed_rotation = False
sensor.fixed_calibration = True
# Load camera positions
chunk.crs = Metashape.CoordinateSystem("EPSG::21781")
loadReferenceSuccess = chunk.importReference('camera_positions_rotations.txt', Metashape.ReferenceFormatCSV, "nxyzabc", delimiter=',',crs=chunk.crs)
For info, the CSV file contains the following columns: Labels, E, N, z, Omega, Phi, Kappa.
But I have issues with number 5. The following code only results in invalid tie points:
chunk.matchPhotos()
chunk.alignCameras()
whereas running 'Align Photos' in the GUI result in similar tie points, but which are valid. Is there any additional step performed by 'Align Photos' that I am missing?
I also could not find how to do 4 with the API. How can I make sure that the initial orientations are taking into account (not only positions). In the GUI, this does not seem to be the default.
Thanks!