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

robertomstocker

• Newbie
• • Posts: 6 (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.chunkcamera = chunk.cameraspoint2D = PhotoScan.Vector([imgX,imgY]) # coordinates of the point on the given photosensor = camera.sensorcalibration = sensor.calibrationx = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D)))`

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.chunkpointWorld2D = 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 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.documentchunk = doc.chunkcamera = chunk.cameraspoint2D = PhotoScan.Vector([imX, imY])sensor = camera.sensorv = chunk.model.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D)))v_t = chunk.transform.matrix.mulp(v)v_t.size = 3v_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 = 3v_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