Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: willcodeforfoo on May 31, 2022, 05:31:21 PM

Title: Camera coordinate (x, y) to Orthomosaic coordinate (x, y)
Post by: willcodeforfoo on May 31, 2022, 05:31:21 PM
Is it possible (maybe through pickPoint, camera.transform, etc.) to somehow determine which x, y coordinate in the orthomosaic corresponds to a given camera's x, y coordinate (if any?)

Thanks!
Title: Re: Camera coordinate (x, y) to Orthomosaic coordinate (x, y)
Post by: Alexey Pasumansky on May 31, 2022, 06:43:29 PM
Hello willcodeforfoo,

Can you please specify, if you mean pixels for XY orthomosaic coordinates, or whether X and Y are in geographic/local coordinates?

Also specify, whether the surface used for the orthomosaic generation is available (may be required to estimate Z value for the point of interest), and which projection method is used for orthomosaic generation.
Title: Re: Camera coordinate (x, y) to Orthomosaic coordinate (x, y)
Post by: willcodeforfoo on May 31, 2022, 10:44:31 PM
Alexey, Thanks for the reply!

Ortho would be generated in geographic projection with WGS84 from DEM and I'm interested in the XY coordinates in the ortho, not really interested in Z.
Title: Re: Camera coordinate (x, y) to Orthomosaic coordinate (x, y)
Post by: Paulo on June 01, 2022, 02:40:48 PM
Hello will,

Given a chunk with a given camera with a point with (x,y) pixel coordinates then you can use the surface that was the base for DEM generation

surface = chunk.model or surface = chunk.dense_cloud
so projected point p on surface woud be
p = surface.pickPoint(center,p2) # projected point p on surface in internal coordinate system
where center = camera.unproject(ps.Vector((x,y,0))) # camera perspective center coordinates in internal CS and
p2 = camera.unproject(ps.Vector((x,y,1))) # coordinates of point in direction from (x,y) to camera center in internal CS

P = ortho.crs.project(T.mulp(p)) # coordinates of projected point in ortho projection
X, Y  = (P.x, P.y) # point P X,Y coordimates  in ortho CS
where ortho = chunk.orthomosaic and T = chunk.transform.matrix

This should get you going,

PS this supposes projected point on surface exists ie. is inside same