Forum

Author Topic: How to map a pixel in a orthophoto to the original images  (Read 2019 times)

yangjie

  • Newbie
  • *
  • Posts: 1
    • View Profile
How to map a pixel in a orthophoto to the original images
« on: July 27, 2018, 12:29:49 AM »
Hi,

I am new to Agisoft and didn't finish all the Python tutorial yet, but would like to know if it is possible to map a pixel in a orthophoto to all the original images. For example, if I detect an object in the orthophoto using an object detection model, can I easily extract the same object from all the original images? Which input file shall I use? Is there any Python script example I can study?

Thanks a lot!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to map a pixel in a orthophoto to the original images
« Reply #1 on: September 19, 2018, 09:49:19 PM »
Hello yangjie,
If you have drawn the point shape on the orthomosaic and want to get it's coordinates on the source images you should at first use "update altitude" command from teh shape context menu in the Ortho view mode to ensure that shape vertex has all three coordinates and then execute the following code (providing that you have only one shape in the active chunk):

Code: [Select]
import PhotoScan
chunk = PhotoScan.app.document.chunk
shape = chunk.shapes[0]
T = chunk.transform.matrix
crs = chunk.crs
point = shape.vertices[0]
point_local = T.inv().mulp(chunk.crs.unproject(point))
for camera in chunk.cameras:
if not camera.transform:
continue
x, y  = camera.project(point_local)
if (0 <= x < camera.sensor.width) and (0 <= y < camera.sensor.height):
print(camera.label, str(x), str(y))

This code will output the XY coordinates of your original point shape on each image where this point is visible on.
Best regards,
Alexey Pasumansky,
Agisoft LLC