1
Python and Java API / Re: Exporting Chunks as Georeferenced Orthophotos
« on: July 17, 2014, 05:00:53 PM »
Alexey,
This may not be the most pythonic or efficient way to do this but it is working great for me, I put it into a function to make this super simple. Thank you so much!
This may not be the most pythonic or efficient way to do this but it is working great for me, I put it into a function to make this super simple. Thank you so much!
Code: [Select]
def toMeters(res):
if res != float(res):
return 0
else:
try:
#recalculating WGS84 resolution from degrees into meters
crd = chunk.ground_control.locations[chunk.cameras[0]].coord #first image coordinates, should be aligned
#longitude
v1 = PhotoScan.Vector((crd[0], crd[1], 0) )
v2 = PhotoScan.Vector((crd[0] + 0.001, crd[1], 0))
vm1 = chunk.crs.unproject(v1)
vm2 = chunk.crs.unproject(v2)
res_x = (vm2 - vm1).norm() * 1000
#latitude
v2 = PhotoScan.Vector( (crd[0], crd[1] + 0.001, 0))
vm2 = chunk.crs.unproject(v2)
res_y = (vm2 - vm1).norm() * 1000
#export resolution (meters/pix)
d_x = res / res_x
d_y = res / res_y
return [d_x, d_y]
except IndexError:
return 0
Returning 0 means it failed, otherwise it returns the x and y resolution in a list.