Forum

Author Topic: Difference between GUI "Align Photos" and API matchPhotos + alignCameras  (Read 2668 times)

adehecq

  • Newbie
  • *
  • Posts: 8
    • View Profile
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:
Code: [Select]
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:
Code: [Select]
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!

3DWinter

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Difference between GUI "Align Photos" and API matchPhotos + alignCameras
« Reply #1 on: November 24, 2020, 04:06:42 AM »
Did you figure it out?

In my reference file, there are six columns (Filename, East, North, Alt, erroX,errorY). In the GUI you tell what column is what( Label=column 1, East=2' etc'), unclear how to define that in Python!?




Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: Difference between GUI "Align Photos" and API matchPhotos + alignCameras
« Reply #2 on: November 24, 2020, 12:21:25 PM »
If the OPK angles should be imported, it is necessary to switch the default Yaw, Pitch, Roll angles using the following line:
Code: [Select]
chunk.euler_angles = Metashape.EulerAnglesOPK
In order to "check on" coordinate information and camera orientation angles in the Reference pane the following lines should be used:
Code: [Select]
for camera in chunk.cameras:
    if camera.reference.location:
        camera.reference.location_enabled = True
    if camera.reference.rotation:
        camera.reference.rotation_enabled = True


As for the main question: the equivalent of Align Photos GUI operation is the consecutive execution of matchPhotos and alignCameas operations.
Best regards,
Alexey Pasumansky,
Agisoft LLC