Forum

Author Topic: Photo extent in orthomosaic  (Read 951 times)

william

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
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:

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?



Paulo

  • Hero Member
  • *****
  • Posts: 1105
    • View Profile
Re: Photo extent in orthomosaic
« Reply #1 on: May 02, 2021, 03:22:28 AM »
Hi william,

the crs coordinates of corners will be in this order:
- 1st corner coordinates will correspond to (0,0) in image;
- 2nd corner coordinates will correspond to (4000,0) in image;
- 3rd corner coordinates will correspond to (4000,3000) in image;
- 4th corner coordinates will correspond to (0,3000) in image.

How this polygon will be oriented will obviously depend on how the camera is oriented. See attachment for  better understanding.

Actually your corner coordinates as defined by the mentioned script  will correspond to
photo_coords (px)      
(0, 0)   
(3999, 0)   
(3999, 2999)   
(0, 2999)   
Best Regards,
Paul Pelletier,
Surveyor

william

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: Photo extent in orthomosaic
« Reply #2 on: May 03, 2021, 10:42:52 PM »
Thanks paulo.

We re-evaluated our work, and it turns out that the combination of the output of our script PLUS the camera.orientation value is enough to give us the ortho_coords in the correct order.