Author Topic: Different results from GUI and API Python  (Read 1431 times)


  • Newbie
  • *
  • Posts: 1
    • View Profile
Different results from GUI and API Python
« on: September 16, 2022, 01:47:05 PM »
Dear all,

Iam relatively new in using Agisoft Metashape. And now I've stumbled across one thing that I don't quite understand.

I want to perform an alignment of several undistorted image pairs:
For test reasons I tryed once with the GUI and once with the API Python.
And here comes what I dont understand - the results are different.

What am I doing in the API is:
a) I choose 2 images from two different sensors installed in a stereo-capable arrangement, which are already undistorted.
b) I tell Agisoft some adjustments provided by a JSON-file. e.g. camera constant, sensor pixel size, img height/width, principle points, ...
c) I define a scalebar to tell Agisoft that camera 1 is installed at location [0,0,0] and camera 2 at [0.2,0,0] of my local coordinate system

Code: [Select]
    MyProject.settingsFromJSON(filePath=JSONpath, stereoProject=True)

                imageDir             = imageDir,
                fileType             = ".tiff")


    for i, camera in enumerate(MyProject.chunk.cameras):
        camkey              = list(MyProject.camArray.keys())[i]
        sensor              = MyProject.chunk.addSensor()
        sensor.label        = camkey
        sensor.type         = camera.sensor.type
        sensor.calibration  = camera.sensor.calibration
        sensor.width        = camera.sensor.width
        sensor.height       = camera.sensor.height
        sensor.focal_length = MyProject.camArray[camkey]['camConstant']
        sensor.pixel_height = MyProject.camArray[camkey]['pixelSize']
        sensor.pixel_width  = MyProject.camArray[camkey]['pixelSize']
        sensor.fixed_calibration = True
        camera.sensor       = sensor
        calib            = Metashape.Calibration()
        principleX          = MyProject.camArray[camkey]['principleX']
        principleY          = MyProject.camArray[camkey]['principleY']            = principleX/sensor.pixel_height            = principleY/sensor.pixel_height
        calib.f             = sensor.focal_length/sensor.pixel_height
        calib.height        = MyProject.camArray[camkey]['imgHeight']
        calib.width         = MyProject.camArray[camkey]['imgWidth']

        sensor.user_calib   = calib
        sensor.fixed_calibration = True
        camera.sensor = sensor
    scalebar = MyProject.chunk.addScalebar(MyProject.chunk.cameras[0],

    scalebar.reference.distance = 0.2
    scalebar.reference.accuracy = 0.1


d) I try to perform the steps matchPhotos and alignPhotos using the API

Code: [Select]
    MyProject = PyExpress.photogrammicProcessing.processing.matchPhotos(
                project              = MyProject,
                detailLevel          = 0,
                generic_preselection = False,
                ref_preselection     = False,
                filter_stat_tie_pp   = False,
                keypoint_limit       = 10000,
                tiepoint_limit       = 5000,
                guided_matching      = False)

   --> which runs:     project.chunk.matchPhotos(
    MyProject = PyExpress.photogrammicProcessing.processing.alignCameras(
                project              = MyProject,
                adaptive_fitting     = False,
                reset_alignment      = False)

e) Finally, I save everything in an Agisoft project using something like


However, with some of my image-pairs this works pretty good. And with some not.

Now comes the blackbox-moment (also compare to the attachements pls):
  • I open the created .psx-file in the GUI
  • I understand that no alignment has been performed
  • So I try alignment again by using Workflow/AlignPhotos within the GUI + checking the box "reset current alignment"
  • Here it works, ...,  :o :o :o.

I ve tryed to implement exactly the same what the GUI is doing when running "Align Photos". Where am I missing something here?

I hope I have expressed myself clearly  ::) :)

Thank you very much in advance,
« Last Edit: September 16, 2022, 02:04:26 PM by MartinKobe »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14489
    • View Profile
Re: Different results from GUI and API Python
« Reply #1 on: October 13, 2022, 08:55:14 PM »
Hello Martin,

Have you checked that the sensor information is properly applied by your script?

If you would like to replicate in script the behavior of Align Photos operation with "reset current alignment" option enabled, you need to use matchPhotos with reset_matches=True argument and alignCameras with reset_alignment=False option. These parameters are available in the latest API (version 1.8.4).

In older versions, it was necessary to remove the tie point cloud before running matchPhotos command:
Code: [Select]
chunk.point_cloud = Noneand to reset alignment for all cameras:
Code: [Select]
for camera in chunk.cameras:
   if camera.type == Metashape.Camera.Type.Regular:
      camera.transform = None
Best regards,
Alexey Pasumansky,
Agisoft LLC