Forum

Author Topic: Converting drone image pixels to a global coordinate (lat and long)  (Read 4020 times)

gurjar

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hi,  I am currently working on a project involving a drone's RGB images and need assistance in converting pixel coordinates from the image into the world coordinate system.

Could you please provide guidance or support regarding this matter? Your expertise in this area would be highly valuable to the success of my project.

Thank you in advance for your time and assistance.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15086
    • View Profile
Re: Converting drone image pixels to a global coordinate (lat and long)
« Reply #1 on: November 17, 2023, 07:14:16 PM »
Hello gurjar,

Below you can see an example of the script below, that returns 3D coordinates based on pixel coordinates on the first image:

Code: [Select]
import Metashape

points = [(10,10), (10,500), (500,500), (500,10)]
chunk = Metashape.app.document.chunk
crs = chunk.crs
T = chunk.transform.matrix

N = 0 #for the first camera in chunk
camera = chunk.cameras[N]

if chunk.model:
    surface = chunk.model
elif chunk.point_cloud:
    surface = chunk.point_cloud
else:
    surface = chunk.tie_points

vertices = list()


for point in points:
    x, y = point
    ray_origin = camera.unproject(Metashape.Vector([x, y, 0]))
    ray_target = camera.unproject(Metashape.Vector([x, y, 1]))
    point3D = surface.pickPoint(ray_origin, ray_target)
    if not point3D:
        continue #skip
    point3D = crs.project(T.mulp(point3D))
    vertices.append(point3D)

print(vertices)
print("Script finished")
Best regards,
Alexey Pasumansky,
Agisoft LLC