Forum

Author Topic: Python created pointcloud has large discrepancy to GUI?  (Read 5926 times)

Braeden

  • Newbie
  • *
  • Posts: 24
    • View Profile
Python created pointcloud has large discrepancy to GUI?
« on: January 22, 2024, 09:31:22 AM »
I am running into an issue fairly often that the pointcloud created with python is inaccurate, in some cases by meters. The same cameras run through the GUI (with a batch process) is giving accurate results consistently.

Attached are side by side:
Camera location reports, LHS python with 2.5Meter camera location errors, and RHS Batch Processed with 5cm camera location errors.

Of note (?) when I open the python processed project, it lists all of the camera accuracies as 10m, whereas the batch processed project lists updated accuracies for each camera.
Metashape gui opened after running python workflow on LHS, batch processed project on RHS


Batch process xml attached. Python below.

Any help is appreciated.


 
Code: [Select]
    chunk = doc.addChunk()
    chunk.addPhotos(photos)

    coordinateSystem = "COMPD_CS[\"CCMP + Geoid09\",PROJCS[\"GDA94 / MGA zone 55\",GEOGCS[\"GDA94\",DATUM[\"Geocentric Datum of Australia 1994\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6283\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9102\"]],AUTHORITY[\"EPSG\",\"4283\"]],PROJECTION[\"Transverse_Mercator\",AUTHORITY[\"EPSG\",\"9807\"]],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"28355\"]],VERT_CS[\"AHD height\",VERT_DATUM[\"Australian Height Datum\",2005,AUTHORITY[\"EPSG\",\"5111\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"5711\"]]]"
    Metashape.CoordinateSystem.addGeoid(input_directory + "\\AUSGeoid09.tif" )

    try:
        my_sensor = chunk.sensors[0]
        my_sensor.type = Metashape.Sensor.Type.Frame
        my_calib = Metashape.Calibration()
        my_calib.width = my_sensor.width
        my_calib.height = my_sensor.height
        my_calib.load(str(cameraCalibration[0]), format=Metashape.CalibrationFormatXML)
        my_sensor.user_calib = my_calib
    except IndexError as e:
            print("Problem loading camera calibration .xml from project folder, press enter to continue anyway")
            input()

    for camera in chunk.cameras:
        camera.sensor = my_sensor

    chunk.matchPhotos(progress = progress_print, keypoint_limit = 70000, tiepoint_limit = 7000, downscale=0, generic_preselection = True, reference_preselection = True, reference_preselection_mode=Metashape.ReferencePreselectionSource, filter_mask=False, filter_stationary_points=True, keypoint_limit_per_mpx=1000, guided_matching=False,   )

    chunk.alignCameras(progress = progress_print, adaptive_fitting = False, reset_alignment = False)

    chunk.buildDepthMaps(progress = progress_print, downscale = 8, filter_mode = Metashape.NoFiltering)
    chunk.buildPointCloud(progress = progress_print, source_data=Metashape.DepthMapsData, point_colors=True, point_confidence=False,
    keep_depth=True, uniform_sampling=True, points_spacing=0.05)


    if chunk.point_cloud:
        chunk.exportPointCloud(output_folder + '/' + projectName + '.laz', crs = Metashape.CoordinateSystem(coordinateSystem), format = Metashape.PointCloudFormatLAZ, source_data = Metashape.PointCloudData)





Braeden

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Python created pointcloud has large discrepancy to GUI?
« Reply #1 on: January 23, 2024, 04:53:37 AM »
It seems all of the python processed pointclouds are coming in bowed, down in the middle and up towards two corners. Much more obvious on larger flight areas.

Processing Reports seem to indicate that all processing options are the same, barring software version. Python using: Software version 2.0.4 build 17434, batch processed using: Software version 2.0.1 build 15925

The reports also show the python Camera Location errors are higher, double or more fairly consistently.

Anyone have any ideas? This unfortunately means we currently can't use python to process data.

Paulo

  • Hero Member
  • *****
  • Posts: 1613
    • View Profile
Re: Python created pointcloud has large discrepancy to GUI?
« Reply #2 on: January 23, 2024, 04:33:36 PM »
Hello Braeden,

it seems that in python loading photos does not load the DJI XMP accuracy as it does in GUI (with relevant option set in Advanced  Preferences). To have same weight attached to camera locations in both GUI batch and python I would sugeest for each camera to load accuracy from DJI metadata as in  following code :
Code: [Select]
camera = chunk.cameras[0]
camera.reference.location_accuracy = Metashape.Vector((float(camera.photo.meta['DJI/RtkStdLon']),float(camera.photo.meta['DJI/RtkStdLat']),float(camera.photo.meta['DJI/RtkStdHgt'])))

Also to have a good result I suggest you do an optimizeCameras in API or optimize Alignment in batch....

Maybe this will get you comparable results...
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15702
    • View Profile
Re: Python created pointcloud has large discrepancy to GUI?
« Reply #3 on: January 23, 2024, 04:59:35 PM »
Hello Braeden,

I also suggest to define the path to the geoid file via addGeoid before assigning the coordinate system variable that should use that geoid.
Best regards,
Alexey Pasumansky,
Agisoft LLC