Forum

Author Topic: buildOrthomosaic with custom planar projection matrix  (Read 4182 times)

James

  • Hero Member
  • *****
  • Posts: 766
    • View Profile
buildOrthomosaic with custom planar projection matrix
« on: October 20, 2021, 02:27:45 PM »
Hi there, I had this script which worked well back in version 1.4, and which i have to tried to update to work with 1.7.

Here is the minimal version, which simply tries to buildOrthomosaic using a front projection, instead of the 'standard' top projection:

Code: [Select]
>>> import Metashape
>>> app = Metashape.app
>>> myProjection = Metashape.OrthoProjection()
>>> myProjection.type = Metashape.OrthoProjection.Type.Planar
>>> myProjection.matrix = Metashape.Matrix([[1, 0, 0, 0],[0, 0, 1, 0],[0, -1, 0, 0],[0, 0, 0, 1]])
>>> chunk = app.document.chunks[25]
>>> chunk.buildOrthomosaic(projection=myProjection,surface_data=Metashape.DataSource.ModelData,blending_mode=Metashape.BlendingMode.MosaicBlending)

whatever I plug in to the projection.matrix seems to have no effect on the generated orthomosaic.

There is a difference in the console output if i do this through the python console/script or though the GUI, which is that my script always  generates console output like this:

Code: [Select]
2021-10-20 12:16:18 BuildOrthomosaic: surface = Mesh, blending mode = Mosaic, refine seamlines = 0, ghosting filter = 0, resolution = 0
2021-10-20 12:16:18 initializing...
2021-10-20 12:16:18 Generating orthomosaic...
2021-10-20 12:16:18 Analyzing mesh...

Whereas using the GUI command to build orthomosaic i get output which explicitly declares that it is using a planar projection:

Code: [Select]
2021-10-20 12:19:14 BuildOrthomosaic: projection = Planar, surface = Mesh, blending mode = Mosaic, refine seamlines = 0, ghosting filter = 0, pixel size = 0.0010505 x 0.0010505
2021-10-20 12:19:14 Generating orthomosaic...
2021-10-20 12:19:14 initializing...
2021-10-20 12:19:14 Analyzing mesh...

I'd be so happy if i could just set my projection plane in the batch command window and not deal with python!

James

  • Hero Member
  • *****
  • Posts: 766
    • View Profile
Re: buildOrthomosaic with custom planar projection matrix
« Reply #1 on: October 20, 2021, 04:27:13 PM »
I realise I didn't really ask a question, so my question is:

Is this a bug, or is there a way to use buildOrthomosaic in python such that a front (or any other) projection can be used, as can be done in the GUI?

Paulo

  • Hero Member
  • *****
  • Posts: 1359
    • View Profile
Re: buildOrthomosaic with custom planar projection matrix
« Reply #2 on: October 20, 2021, 07:41:02 PM »
Hi James,

I have found for a  planar projection to work in python, you need to specify the crs attribute of Metashape.OrhoProjection() type.

so in your case you would need to add some lines in your code:
Code: [Select]
if chunk.crs.geoccs != None:
myProjection.crs = chunk.crs.geoccs # case of georeferenced project
else:
myProjection.crs = chunk.crs        # case of Local CS project
Hope this helps,
« Last Edit: October 20, 2021, 08:37:22 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

James

  • Hero Member
  • *****
  • Posts: 766
    • View Profile
Re: buildOrthomosaic with custom planar projection matrix
« Reply #3 on: October 20, 2021, 10:31:26 PM »
That's it! Amazing, thank you!

Now I can leave this script running and sleep, rather than stay up all night running each one manually!