Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AndrewNeubauer

Pages: [1]
1
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!

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.

2
Thanks for the reply Alexey,

I did not realize that, I need to export using resolution in meters, and all of the chunk sizes are different. How should I go about doing that? Am I going to have to calculate that in the script, and if so, how?

3
Python and Java API / Exporting Chunks as Georeferenced Orthophotos
« on: July 16, 2014, 06:29:00 PM »
I am pretty new to python so please forgive me. What I am trying to achieve here is generate orthophotos for all chunks, generating a tif and kmz for chunks which name ends in "RGB" and just a tif for those that end in"NIR". The loop seems to be working correctly as it goes through everyone like it should but there is no file and the console says it exported at 0 x 0 pixels.

My Current Script:
Code: [Select]
from PhotoScan import *

print("This Script will export all chunks into the selected folder")

doc = PhotoScan.app.document


CoordinateSystemEPSG = "EPSG::4326"
CoordinateSystem = PhotoScan.CoordinateSystem()
CoordinateSystem.init(CoordinateSystemEPSG)

def getDir(name):
dir = PhotoScan.app.getExistingDirectory(name)
if dir == '':
print("Must provide a valid directory")
return
return dir


saveFolder = getDir("Select Save Folder")




print("---Exporting Orthoimage(s)...")

for chunk in doc.chunks:
file = saveFolder + "\\"  + chunk.label
print("File: " + file)

if chunk.label[-3:] == "RGB":
chunk.exportOrthophoto(file + ".tif", format="tif", blending="mosaic", projection=CoordinateSystem, dx=0.2, dy=0.2)
chunk.exportOrthophoto(file + ".kmz", format="kmz", blending="mosaic", projection=CoordinateSystem, dx=0.05, dy=0.05, write_kml= True)
elif chunk.label[-3:] == "NIR":
chunk.exportOrthophoto(file + ".tif", format="tif", blending="mosaic", projection=CoordinateSystem, dx=0.2, dy=0.2)
else:
app.messageBox("Exporting orthoimage failed: " + chunk.label)

The console spits out this (multiple times):
Code: [Select]
File: ****\** RGB
initializing renderer... tessellating mesh...done (335152 -> 335152 faces)
done in 0.338 sec
Raster size: 0x0
Finished processing in 0.355 sec (exit code 0)
initializing renderer... tessellating mesh...done (335152 -> 335152 faces)
done in 0.364 sec
Raster size: 0x0
Finished processing in 0.364 sec (exit code 0)
File: ****\** NIR
initializing renderer... tessellating mesh...done (342265 -> 342265 faces)
done in 0.295 sec
Raster size: 0x0
Finished processing in 0.295 sec (exit code 0)

Pages: [1]