Forum

Poll

How do you build an ortho-mosaic with markers?

Build Ortho mosaic with markers
0 (0%)
Build Ortho mosaic with markers
1 (100%)

Total Members Voted: 1

Author Topic: Build Ortho mosaic with markers  (Read 1240 times)

Natsumi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Build Ortho mosaic with markers
« on: August 04, 2021, 03:54:51 AM »
Hello everyone,

First of all, Please forgive me that my English is not very good.

I want to run a build Orthomosaic in a script.
But I don't know how to specify projection markers or horizontal axis or vertical axis.
How do you specify it in python?

Please let me know if you don't understand the question.

Thank you in advance!

Natsumi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Build Ortho mosaic with markers
« Reply #1 on: August 04, 2021, 04:06:30 AM »
Hello everyone,

First of all, Please forgive me that my English is not very good.

I want to run a build Orthomosaic in a script.
But I don't know how to specify projection markers or horizontal axis or vertical axis.
How do you specify it in python?

Please let me know if you don't understand the question.

Thank you in advance!

Paulo

  • Hero Member
  • *****
  • Posts: 776
    • View Profile
Re: Build Ortho mosaic with markers
« Reply #2 on: August 04, 2021, 08:02:26 PM »
Hello Natsumi,

given 3 markers (m1 = <Marker '1'>, m2 = <Marker '2'>, m3 = <Marker '3'>) that you want to use as horizontal axis (1-2) and vertical axis(1-3) in BuildOrthomosaic from Model surface then following code would do the trick:
Code: [Select]
def cross(a, b):
result = Metashape.Vector([a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y *b.x])
return result.normalized()
 
chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
horizontal = T.mulp(m2.position) - T.mulp(m1.position)  # markers m1, m2 define horizontal axis
vertical = T.mulp(m3.position) - T.mulp(m1.position)      # markers m1, m3 define vertical axis
normal = cross(horizontal, vertical)
vertical = -cross(horizontal, normal)
horizontal = horizontal.normalized()
orthoproj = Metashape.OrthoProjection()
if chunk.crs.geoccs:
    orthoproj.crs = chunk.crs.geoccs # case of georeferenced project
else:
    orthoproj.crs = chunk.crs       # case of Local CS project
R = Metashape.Matrix ([horizontal, vertical, normal])
t = R*T.mulp(m1.position)
orthoproj.matrix = Metashape.Matrix.Translation(-t)*Metashape.Matrix.Rotation(R)
chunk.buildOrthomosaic(surface_data=Metashape.ModelData,  projection = orthoproj)

see attachmnet...

« Last Edit: August 04, 2021, 10:00:35 PM by Paulo »
Best Regards,

Paul Pelletier

Natsumi

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Build Ortho mosaic with markers
« Reply #3 on: August 05, 2021, 07:25:56 AM »
Thanks Paulo,

The code you taught me works very well.
Thanks so much.