Forum

Author Topic: Python script of a full process  (Read 10112 times)

Will

  • Newbie
  • *
  • Posts: 5
    • View Profile
Python script of a full process
« on: May 31, 2021, 11:15:11 AM »
Hello all,

I'm a new one here.

I have been doing photogrammetry since  6 years but I'm a newbee in programming....

My request here would be to automate the full process that I descibe below. Is it possible?  has something like this ever been scripted? thanks in advance for your answers.


Complete photogrammetric process for agisoft metashape with Python command :

 --- I need a loop of the process describe below of all folders in the specific directory ---

1) In the tool panel -> Workflow → add photos (from a folder)
   Folder directory : (D:) (I will change it myself)

2) in the reference panel  → Convert -> select coordinate system (Belgian Lambert 72 EPSG:31370)

3) In the tool panel -> Workflow -> align photos :

   settings : → Accuracy : High
         → Key Point limit : 64.000
         → Tie point limit : 12.000
   with generic preselection option checked
   with reference preselection option checked

4) In the reference panel :
   → Preference Setting
   → Camera accuracy (m) : 0.1
   → Camera accuracy (deg) : 0.1

5) In the reference panel :
   → Optimize camera : fit f, fit K1, fit K2, fit K3, Fit cx, cy, Fit p1, Fit p2.
   → Fit addictional corrections

6) In the tool panel :
   → Gradual selection : reconstruction Uncertainty → select the level 24
   → Delete selection (delete points)

7) In the reference panel :
   → Optimize camera : fit f, fit K1, fit K2, fit K3, Fit cx, cy, Fit p1, Fit p2.
   → Fit addictional corrections (delete points)

8) In the tool panel :
   → Gradual selection : projection accuracy → select the 2,5 level
   → Delete selection (delete points)

9) In the reference panel :
   → Optimize camera : fit f, fit K1, fit K2, fit K3, Fit cx, cy, Fit p1, Fit p2.
   → Fit addictional corrections

10) In the reference panel :
   → Preference Setting
   → Tie point Accuracy (pix) : 0.2

11) In the reference panel :
   → Optimize camera : fit f, fit K1, fit K2, fit K3, Fit K4, Fit cx, cy, Fit p1, Fit p2, Fit b1, Fit b2 (all the parameters)
   → Fit addictional corrections

12) In the tool panel :
   → Gradual selection : reprojection error → select the 0.15 level
   → Delete selection (delete points)

13) In the reference panel :
   → Optimize camera : fit f, fit K1, fit K2, fit K3, Fit K4, Fit cx, cy, Fit p1, Fit p2, Fit b1, Fit b2 (all the parameters)
   → Fit addictional corrections

14) In the tool panel -> Workflow -> Build dense cloud :

   settings → Quality : medium
   Depth filtering → Moderate
   with Calculate point colors option checked

15) In the tool panel -> Workflow -> Build DEM :

   Type → geographic
   Belge 1972/Belgian Lambert 72 (EPSG 31370)
   Source data : Dense cloud
   Interpolation : Enabled (default)
   Point classes : all
   with Setup boundaries unchecked
   Resolution (m) by default
   Total size (pix) : by default

16) In the tool panel -> Workflow -> Build Orthomosaic :

   Type → by default
   Surface → DEM
   Blending mode : Mosaic (default)
   with refine seamlines unchecked
   with Enable hole filing checked
   Pixel size (m) by default
   with Max. dimension (pix) unchecked
   Setup boundaries unchecked
   Total size (pix) unchecked

   Interpolation : Enabled (default)
   Point classes : all
   with Setup boundaries unchecked
   Resolution (m) by default
   Total size (pix) : by default

17) File → Export → Export Points

   select ASPRS LAS (*.las)
   File directory : local disk (D:) (I will change it myself)
   Coordiante System : Belge 1972 / Belgian Lambert 72 (EPSG : 31370)
   Shift X : x:0 - y:0 - z:0
   Source data : dense cloud
   Point classes : All
   With Save point colors checked
   With Save point nomals checked
   With Save point confidence checked
   With Save point classes checked
   With split in blocs (m) checked : 950 x 950
   With clip to boundary shapes unchecked

18) File → Export → Export Orthomosaic → Export JPEG / TIFF / PNG

   Coordiante System : Belge 1972 / Belgian Lambert 72 (EPSG : 31370)
   with pixel size checked with default values
   with Max. dimension (pix) unchecked
   with Split in blocks (pix) checked : 48469 x 48469
   with Background color checked : black
   with Setup boundaries unchecked
   with Total size (pix) default values
   with Write tile scheme unchecked
   with Wrtite World file unchecked
   with No image description
   Tiff Compression : JPEG
   JPEG quality : 99
   with Write tiled TIFF checked
   with Generate TIFF overviews checked
   with Write alpha channel checked
   with Write BigTIFF file checked
   EXTENSION NAME : JPEG2000 (*.jp2)
   File directory : local disk (D:) (I will change it myself)
 
« Last Edit: May 31, 2021, 11:16:42 AM by Will »

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Python script of a full process
« Reply #1 on: June 01, 2021, 03:19:00 PM »
Will,

you could take this script as a starting point. Right now it just deals with one photo directory at a time and is missing build ortho and export ortho phase ... but it can be a good initiation for your python learning experience!

When you run the script, a Custom Menu will appear in Menu bar, click on Custom Menu / Full Process to run...

PS. to speed up your optimizations, I would only use extra or additional corrections option in last optimization after reprojection error gradual selection/delete....
« Last Edit: June 05, 2021, 07:41:43 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Will

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Python script of a full process
« Reply #2 on: June 23, 2021, 03:53:47 PM »
Hello Paulo,

thank you for your answer!! I will start with that and follow your advices :-)

Best regards
William

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Python script of a full process
« Reply #3 on: June 23, 2021, 05:14:06 PM »
We are planning to publish general workflow script example in GitHub after 1.7.4 release (as some extension of Python functionality has been required).

The script would be based on Metashape.Tasks classes and will show the way to use it both for local processing and for network batch creation.
Best regards,
Alexey Pasumansky,
Agisoft LLC

SMcMurray1

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Python script of a full process
« Reply #4 on: July 16, 2021, 07:42:55 AM »
Hi how would you get this script to look in multiple folders nested under one folder for the images ?
Also I cannot seem to find the build Orthomosaic and export Orthomosaic examples for adding them to the script - does anyone have any or can tell me what to put in the script to get it to do this ?
BTW the script is awesome

Regards
Steve

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Python script of a full process
« Reply #5 on: July 17, 2021, 12:56:18 AM »
Hello Steve,

You can try to modify the lines that look for the image files and add them to the project to the code that uses glob module:

Code: [Select]
import glob
TYPES = ["DNG", "JPG", "JPEG", "TIF", "TIFF"]
image_list = [photo for photo in glob.iglob(input_folder + "\\*.*", recursive = True) if os.path.isfile(photo) and os.path.splitext(photo)[1][1:].upper() in TYPES]
Best regards,
Alexey Pasumansky,
Agisoft LLC

SMcMurray1

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Python script of a full process
« Reply #6 on: July 19, 2021, 05:05:54 AM »
Thanks Alexy - would the following code generate the Orthoimage ?
#build Orthomosaic
chunk.buildOrthomosaic(surface_data=Metashape.DataSource.ModelData,blending_mode=Metashape.BlendingMode.MosaicBlending,projection=chunk.crs)

Any help is appreciated


SMcMurray1

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Python script of a full process
« Reply #7 on: July 19, 2021, 08:53:22 AM »
Hi Alexey

I have been trying to modify this script to stop after the alignment and prompt for the import of GCPs then start again once they are selected to then optimise the cameras and continue with the dense cloud, DEM and add an Orthophoto section to the end of it - I cant seem to get it to work though - can you guys add this in for me please my python is not that great !!

Cheers
Steve

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Python script of a full process
« Reply #8 on: August 22, 2021, 02:02:32 PM »
We have published the examples of general workflow script (including the network processing option) in GitHub repository:
https://github.com/agisoft-llc/metashape-scripts/tree/master/src/samples

Note that version 1.7.4 is required.
Best regards,
Alexey Pasumansky,
Agisoft LLC