Forum

Author Topic: Python and GUI not equivalent  (Read 1508 times)

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Python and GUI not equivalent
« on: February 18, 2023, 04:37:46 AM »
Hello,

I am trying to replicate the GUI workflow in Python code, without much success.  The GUI works nicely - see screenshot.  The python code fails to generate depth maps.  I am attaching:
* screenshot of GUI execution (Screen Shot ...)
* python workflow script with my addition for writing out depth maps (sample_scripts_for_depthmaps.txt)
* Output from sample scripts (script_output.txt)
* Camera calibration file for external camera poses and camera intrinsic (cameras_cal_tiny_1.xml)

Would greatly appreciate some help on this.  Otherwise, I will have to run a hybrid GUI-script for 100 image sets!

Many thanks for your response.

VKam

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Python and GUI not equivalent
« Reply #1 on: February 18, 2023, 07:33:24 PM »
Hello VKam,

Seems like the screenshots are missing. Also you can share the code that you are using.
Best regards,
Alexey Pasumansky,
Agisoft LLC

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Python and GUI not equivalent
« Reply #2 on: February 18, 2023, 08:34:04 PM »
Hi Alexey,

Thanks for your response.  See attached -
* Screen shot
* Sample script for exporting depth mals, modified from your example script (general_workflow)
* Output from running the script
* Camera extrinsic and intrinsic ingest

Sorry, I did not attach docs correctly last time.

VKam

ankit108

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Python and GUI not equivalent
« Reply #3 on: February 18, 2023, 10:20:37 PM »
Here is a sample snippet, which generates Depth Map and then build Dense Cloud.
Code: [Select]
#initializing steps

chunk = Metashape.app.document.chunk

#further steps

#Build Depth Map
chunk.buildDepthMaps(quality=Metashape.MediumQuality, filter=Metashape.ModerateFiltering, reuse_depth=False)

#Build Dense Cloud
chunk.buildDenseCloud(point_colors=True, keep_depth=True)


vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Python and GUI not equivalent
« Reply #4 on: February 18, 2023, 11:17:38 PM »
Hello ankit108,

What operations do you execute *before* the buildDepthMaps() call?

For my workflow, I am working with a rigid camera rig.  So I have:
* Read in images with addPhotos()
* Call chunk.importCameras() to read in a calibration file which has intrinsic and extrinsic data for camera rig
* Call chunk.MatchPhotos() (here the GUI and Python diverge - GUI automatically calls buildTiePoints())
* Call chunk.alignCameras() (according to Alexey, calling matchPhotos() an alignCameras() is equivalent to calling GUI alignPhotos())
* call chunk.buildDepthMaps()

VKam

ankit108

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Python and GUI not equivalent
« Reply #5 on: February 19, 2023, 10:11:16 AM »
Hello vkam, My workflow is as follows:

1. Load cameras
2. Load Reference
3. Match Photos
4. Camera Alignment
5. Tie point error optimisation
6. Put the markers (check points)
7. Generate Depth map
8. Build Dense Cloud
9. Bulid DEM
10. Build Ortho
11. Export

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Python and GUI not equivalent
« Reply #6 on: February 19, 2023, 07:56:23 PM »
Hmm your workflow is slightly different, but would you mind sharing the arguments you use to invoke matchPhotos() and alignCameras()?

VKam

ankit108

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Python and GUI not equivalent
« Reply #7 on: February 19, 2023, 09:16:10 PM »
yeah sure,
here you go..

Code: [Select]
chunk.matchPhotos(accuracy=Metashape.HighAccuracy,
                          generic_preselection=True,
                          reference_preselection=True,
                          keypoint_limit=40000,
                          tiepoint_limit=4000,
                          filter_mask=False,
                          mask_tiepoints=False,)

chunk.alignCameras(adaptive_fitting=True,)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Python and GUI not equivalent
« Reply #8 on: February 20, 2023, 04:00:09 PM »
Hello VKam,

If you need to replicate the GUI workflow (Import Cameras from xml, Build Tie Points), then you should use importCameras, matchPhotos and triangulateTiePoints commands (in v. 2.0.0 API), using alignCameras would discard imported exterior and interior orientation parameters and calculation/adjustment will be performed by Metashape.

The script log that you have provided indicates that no depth maps have been generated, so you cannot export them.

If it is a typical problem for any dataset that you have when processed via script, please share a dataset sample (11 images and related XML file) to support@agisoft.com, so that we can check it in detail on our side.
Best regards,
Alexey Pasumansky,
Agisoft LLC

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Python and GUI not equivalent
« Reply #9 on: February 21, 2023, 03:51:37 AM »
Hi Alexey,

Thanks for your response.  I am primarily interested in exporting depth maps for the cameras, while honoring the intrinsic and extrinsic parameters I load.  So I am happy with whatever workflow is suitable for that.

I believe I tried loading photos, loading camera.xml, matchPhotos() and alignCameras() with adaptive_fitting = 0.  It looks like that produced too few matching tie points (<=2!) and so buildDepthMaps() failed.

Will try out this workflow.  Please let me know if there are particular arguments that I need to be careful about.

Thanks,

VKam

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Python and GUI not equivalent
« Reply #10 on: February 21, 2023, 04:19:58 AM »
Hello Alexey,

That worked nicely, thank you!

For the benefit of others who might be interested in working with pre-calibrated camera rigs, I am attaching the workflow that worked for me.

Cheers!

VKam