Forum

Author Topic: Transformation parameters Orthophoto (2D) <-> real world (3D)  (Read 2613 times)

geo_enth3

  • Newbie
  • *
  • Posts: 26
    • View Profile
Hi,

I am currently facing the problem that I have to create orthophotos of vertical structures (walls). I also need these orthophotos to be georeferenced which is why I wanted to ask how and where I can access the transformation parameters from the 2D Orthophoto/Orthomosaic image coordinates to the 3D real world coordinates. I know Metashape stores them somewhere because polygons that are drawn on the (georeferenced) 3D model are displayed perfectly on the orthophoto but I don't know how to access those. Ideally the transformation parameters would be accessible via the python api.

If you have any hints on how to achieve this, I would be very happy.

Best,

geo_enth
« Last Edit: June 07, 2022, 02:02:03 PM by geo_enth3 »

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #1 on: June 07, 2022, 03:27:01 PM »
H geo_enth3,

the transformation from the 3d geocentric coordinates (EPSG::4978) to ortho planar coordinates is given by following transformation matrix:
Code: [Select]
P = chunk.orthomosaic.projection.matrix
However this is a 3d to 3d transformation. So to go from planar projection ortho 2d coordinates you need to recover the planar projection Z either by building the planar projection dem (where height is perpendicular distance from planar wall) or use pickPoint method with chunk model....

Some script could be developed for this...

Example of point p on planar ortho of side of a building with pixel coordinates (577.3,415.33) and its resulting World 3d coordinates (using both planar DEM and model)... see attachment...

PS. this supposes your model is georeferenced...

« Last Edit: June 07, 2022, 05:36:40 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

geo_enth3

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #2 on: June 07, 2022, 04:12:41 PM »
Hi,

thanks for the quick reply and the help! After doing some research I am now one step closer to the solution of my problem:

Within the OrthoProjection class there is also the transform function (see screenshot). As I understand this function allows me to apply the transformation from the 2D Ortho coordinates to the 3D world coordinates (by applying the transformation matrix you posted in your answer)

In my understanding, applying the following code should return me the 3D world coordinates (in the chunk's crs) of the upper left corner of the orthophoto (0,0)

Code: [Select]
point2D_img = Metashape.Vector([0,0])
source_crs = chunk.orthomosaic.projection.crs
target_crs = chunk.crs
point3D_world = chunk.orthomosaic.projection.transform(point2D_img, source_crs, target_crs)

I am, however, receiving the following type error;
Code: [Select]
TypeError: transform() argument 2 must be Metashape.OrthoProjection, not Metashape.CoordinateSystem
Do you have an idea to solve this issue?

Best,

geo_enth
« Last Edit: June 07, 2022, 05:38:22 PM by geo_enth3 »

geo_enth3

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #3 on: June 07, 2022, 05:51:20 PM »
Thanks for the example.   Could you maybe provide me with the complete code as well?

Best,

geo_enth

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #4 on: June 07, 2022, 05:55:33 PM »
geo_enth3,

please send me a PM (personal message) for further discussion...

Best Regards,
Paul Pelletier,
Surveyor

geo_enth3

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #5 on: June 07, 2022, 06:01:58 PM »
Done

geo_enth3

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #6 on: June 07, 2022, 06:56:50 PM »
To make my problem clearer I am providing an example of what I am looking for:

Screenshot A: marker placed on the 3D model
Screenshot B: same marker displayed in the orthophoto

between A and B must be a transformation (matrix) which I am trying to access.

I hope this makes my problem clearer


Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #7 on: June 07, 2022, 08:21:14 PM »
Hello again,

from 3d model to 2d ortho planar projection is quite straightforward:
Code: [Select]
chunk = ps.app.document.chunk
ortho = chunk.orthomosaic # planar projection ortho of your wall
P = ortho.projection.matrix
T = chunk.transform.matrix
pt = chunk.markers[0] # given example point marker
pt_geoc = T.mulp(pt.position) # coordinates of example point marker in geocentric cs (chunk.crs.geoccs) (case georeferenced project) or in Local cs (chunk.crs) (case Local project)
pt_ort = P.mulp(pt_geoc)[0:2] # coordinates of  example point marker in planar projection ortho
from 2d ortho to 3d model or  world coordinates is more complex as you have to extract Z component....
« Last Edit: June 16, 2022, 11:57:18 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Transformation parameters Orthophoto (2D) <-> real world (3D)
« Reply #8 on: June 14, 2022, 03:55:06 PM »
geo_enth3,
Hello again,

from 3d model to 2d ortho planar projection is quite straightforward:
Code: [Select]
chunk = ps.app.document.chunk
ortho = chunk.orthomosaic # planar projection ortho of your wall
P = ortho.projection.matrix
T = chunk.transform.matrix
pt = chunk.markers[0] # given example point marker
pt_geoc = T.mulp(pt.position) # coordinates of example point marker in geocentric cs (chunk.crs.geoccs) or local cs (case of Local referenced project)(chunk.crs)
pt_ort = P.mulp(pt_geoc)[0:2] # coordinates of  example point marker in planar projection ortho
from 2d ortho to 3d model or  world coordinates is more complex as you have to extract Z component....
In case of georeferenced chunk, the ortho projection matrix P  transforms a point in geocentric coordinates to the ortho planar projection coordinates. In case of Local referenced chunk, the ortho projection matrix P  transforms a point in Local coordinates to the ortho planar projection coordinates. It is a 4 by 4 matrix containing a 3 by 3 rotation R plus a 3 by 1 translation T in homogeneous form  as in attachement:


« Last Edit: June 17, 2022, 12:00:32 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor