Forum

Author Topic: From world coordinates to pixel coordinates  (Read 2756 times)

JulienGroenenboom

  • Newbie
  • *
  • Posts: 7
    • View Profile
From world coordinates to pixel coordinates
« on: October 17, 2014, 03:42:06 PM »
Hello,

I have tried to use a couple of (adjusted) scripts that were available at the forum, but I didn't work for me... So I hope that someone can give me a hint or script that can help me out.

I would like to transform georeferenced coordinates(x,y,z) in my model to pixel coordinates(somewhere between 0-width,0-height) on a certain photo. I use coordinatesystem EPSG::28992.

I have tried the scripts below, but they didn't give the right pixel coordinates.

Code: [Select]
import PhotoScan as ps

crs = PhotoScan.CoordinateSystem()
crs.init("EPSG::28992")

#test1
photo_0 = ps.app.document.activeChunk.photos[0]

currentChunk  = PhotoScan.app.document.activeChunk
point_geocentric = currentChunk.projection.unproject(PhotoScan.Vector((74183.609,453380.738,3.388)))

(imgx, imgy) = photo_0.project(point_geocentric)
print (imgx, imgy)

#test2
a_camera = photo_0;
transform_matrix = currentChunk.transform * a_camera.transform
point_geocentric.size = 4
point_geocentric[3] = 1
point_local = transform_matrix.inv() * point_geocentric
point_local.size = 3
(image_x, image_y) = a_camera.project(point_local)

print (image_x,image_y)
print("Done")


Thank you in advance.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14110
    • View Profile
Re: From world coordinates to pixel coordinates
« Reply #1 on: October 17, 2014, 04:05:55 PM »
Hello Julien,

I suggest the following:

Code: [Select]
point3D = PhotoScan.Vector([74183.609, 453380.738, 3.388])
point_geocentric = currentChunk.projection.unproject(point3D)
point_internal = currentChunk.transform.inv().mulp(point_geocentric)

imgx, imgy = photo_0.project(point_internal)


Best regards,
Alexey Pasumansky,
Agisoft LLC

JulienGroenenboom

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: From world coordinates to pixel coordinates
« Reply #2 on: October 17, 2014, 04:14:06 PM »
Thank you Alexey, it works.