Forum

Author Topic: (lng, lat) <=> (x, y) photo pixel coordinates conversion  (Read 3614 times)

robertomstocker

  • Newbie
  • *
  • Posts: 6
    • View Profile
(lng, lat) <=> (x, y) photo pixel coordinates conversion
« on: December 10, 2017, 03:50:45 AM »
I'm trying to achieve two coordinate conversions:

1. Using (x, y) from a photo, determine the corresponding (lng, lat) coordinates.

For this part, I believe the code posted here http://www.agisoft.com/forum/index.php?topic=7446.0 should work:

Code: [Select]
chunk = PhotoScan.app.document.chunk
camera = chunk.cameras[0]
point2D = PhotoScan.Vector([imgX,imgY]) # coordinates of the point on the given photo
sensor = camera.sensor
calibration = sensor.calibration
x = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D)))

adding

Code: [Select]
result = chunk.crs.project(x)

I can't find the "pickPoint" function in the API Reference document, but would this return the expected result?

2. Using a (lng, lat) to determine the corresponding (x, y) pixel coordinates in each photo of the project.

For this case, I was thinking on creating a Marker to simplify the code

Code: [Select]
chunk = PhotoScan.app.document.chunk
pointWorld2D = PhotoScan.Vector([lng, lat])
x = crs.unproject(pointWorld2D)
chunk.addMarker(point = x)

and then loop over "marker.projections" to obtain the (x, y) pairs for each camera.

Am I on the correct path?

Thanks!

P.S: This post also gave me a couple of clues: http://www.agisoft.com/forum/index.php?topic=6053.msg29355#msg29355

robertomstocker

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: (lng, lat) <=> (x, y) photo pixel coordinates conversion
« Reply #1 on: December 10, 2017, 06:25:15 AM »
Ok, I think I got it.

1. From (imX, imY) pixels on camera 0 to v_out_world = (lng, lat, alt) on world map

Code: [Select]
doc = PhotoScan.app.document
chunk = doc.chunk
camera = chunk.cameras[0]
point2D = PhotoScan.Vector([imX, imY])
sensor = camera.sensor
v = chunk.model.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D)))
v_t = chunk.transform.matrix.mulp(v)
v_t.size = 3
v_out_world = chunk.crs.project(v_t)


2. From v_proj = (lng, lat, alt) on world map to camera v_out_pix = (x, y) pixels

Code: [Select]
v_unproj = chunk.crs.unproject(v_proj)
v_inv = chunk.transform.matrix.inv().mulp(v_unproj)
v_inv.size = 3
v_out_pix = sensor.calibration.project(camera.transform.inv().mulp(v_inv))

References:
http://www.agisoft.com/forum/index.php?topic=6176.0
http://www.agisoft.com/forum/index.php?topic=7446.0
http://www.agisoft.com/forum/index.php?topic=6053.msg29355#msg29355