1
Python and Java API / Photo extent in orthomosaic
« on: May 02, 2021, 12:49:52 AM »
Hello,
I need to locate the extent of an input photo, that is the four corners of a camera.photo, within the orthomosaic (in CRS coordinates). So if my photo has size 4000x3000, I need the following output:
The ortho_coords are just fake UTM coordinates. I have the photo_coords, obviously, but I need the ortho_coords, and I need to match them to the photo_coords.
I am using a script written by Alexey Pasumansky created as an answer to this forum post: https://www.agisoft.com/forum/index.php?topic=6662.0. The important part of the script follows:
The corners returned by this script are correct, but the ordering is not guaranteed! The ordering might match my photo_coords if the camera is pointed north, but not if it points south or west or east. Does someone know how I can use the orientation of the camera to put my output corners in the correct order to match the photo_coords?
I need to locate the extent of an input photo, that is the four corners of a camera.photo, within the orthomosaic (in CRS coordinates). So if my photo has size 4000x3000, I need the following output:
photo_coords (px) | ortho_coords (UTM) |
(0, 0) | (500000, 3000000) |
(4000, 0) | (500125, 3000050) |
(4000, 3000) | (5000176, 3000072) |
(0, 3000) | (500034, 3000101) |
The ortho_coords are just fake UTM coordinates. I have the photo_coords, obviously, but I need the ortho_coords, and I need to match them to the photo_coords.
I am using a script written by Alexey Pasumansky created as an answer to this forum post: https://www.agisoft.com/forum/index.php?topic=6662.0. The important part of the script follows:
Code: [Select]
if chunk.dense_cloud:
surface = chunk.dense_cloud
elif chunk.model:
surface = chunk.model
else:
surface = chunk.point_cloud
for camera in chunk.cameras:
if not camera.transform:
continue #skipping NA cameras
sensor = camera.sensor
corners = list()
for i in [[0, 0], [sensor.width - 1, 0], [sensor.width - 1, sensor.height - 1], [0, sensor.height - 1]]:
corners.append(surface.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(PhotoScan.Vector(i)))))
if not corners[-1]:
corners[-1] = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(PhotoScan.Vector(i))))
if not corners[-1]:
break
corners[-1] = chunk.crs.project(T.mulp(corners[-1]))
if not all(corners):
print("Skipping camera " + camera.label)
continue
return corners
The corners returned by this script are correct, but the ordering is not guaranteed! The ordering might match my photo_coords if the camera is pointed north, but not if it points south or west or east. Does someone know how I can use the orientation of the camera to put my output corners in the correct order to match the photo_coords?