Forum

Author Topic: Create cylindrical orthomosaic orientation z axis  (Read 4703 times)

sepehr500

  • Newbie
  • *
  • Posts: 17
    • View Profile
Create cylindrical orthomosaic orientation z axis
« on: May 03, 2022, 12:02:33 AM »
I am trying to create a cylindrical orthomosaic along the z axis. This works great when I do it the UI. "Build orthomosaic" -> "Cylindrical" -> "Cylinder Orientation = z". But I can't figure out how to do this with the Python API. My model is already oriented the right way, so all I need is to emulate this behavior in the API. Any ideas?

Paulo

  • Hero Member
  • *****
  • Posts: 1490
    • View Profile
Re: Create cylindrical orthomosaic orientation z axis
« Reply #1 on: May 03, 2022, 02:12:36 AM »
Hi,

I think in API you use buildOrthomosaic() projection parameter to define ortho projection with rotation as identity and translation as - region.center as:
Code: [Select]
T = chunk.transform.matrix
orthoproj = Metashape.OrthoProjection()
orthoproj.crs = chunk.crs
orthoproj.type = Metashape.OrthoProjection.Type.Cylindrical
R = Metashape.Matrix.Diag([1,1,1])
t = T.mulp(chunk.region.center)
orthoproj.matrix = Metashape.Matrix.Translation(-t)*Metashape.Matrix.Rotation(R)
chunk.buildOrthomosaic(surface_data=Metashape.ModelData,  projection = orthoproj)
It does create the cylindrical ortho along z axis however it does not use the correct width. It is compressed compared  to width of GUI (1741 vs 7771) cylindrical ortho.
See attachment, maybe a bug?

PS. actually not a bug, my error here. You must define the radius of cylinder. In case of cylinder along Z axis then
Quote
Radius (r) is defined as one half of the shortest edge of the Bounding box
so modify above code as follows:
Code: [Select]
T = chunk.transform.matrix
s = T.scale()
orthoproj = Metashape.OrthoProjection()
orthoproj.crs = chunk.crs
orthoproj.radius = min(list(s*chunk.region.size)/2
orthoproj.type = Metashape.OrthoProjection.Type.Cylindrical
R = Metashape.Matrix.Diag([1,1,1])
t = T.mulp(chunk.region.center)
orthoproj.matrix = Metashape.Matrix.Translation(-t)*Metashape.Matrix.Rotation(R)
chunk.buildOrthomosaic(surface_data=Metashape.ModelData,  projection = orthoproj)
and now you get same result  with API as GUI, see 2nd attachment

« Last Edit: May 04, 2022, 04:40:43 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

sepehr500

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Create cylindrical orthomosaic orientation z axis
« Reply #2 on: May 03, 2022, 09:49:19 PM »
Worked perfectly! Just as a heads up sounds there is a typo min(list(s*chunk.region)/2 and missing region.size. Thank you!

Paulo

  • Hero Member
  • *****
  • Posts: 1490
    • View Profile
Re: Create cylindrical orthomosaic orientation z axis
« Reply #3 on: May 04, 2022, 04:40:02 AM »
No problem,

you are right it should be chunk.region.size instead of chunk.region!
Best Regards,
Paul Pelletier,
Surveyor