Hi,
I have put together a script to automate 3D model processing. How do I make sure that my coordinate system is running in wgs84? Also I want the script to ignore adaptive camera fitting setting used in the alignment process. Here the script complaints about saving project in .psx format before processing the dem. Can you please review my code and suggest any changes. Can you also suggest a way to speed up the 3D modeling process, how should I subdivide my data into smaller chunks and do the 3d model build?
thanks,
Tarun
import PhotoScan
import os
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Input/Output folder to save 3D model")
parser.add_argument('--inputpath', '-p', action="store", help="path to photos", required=True)
parser.add_argument('--outputfile', '-o', action="store", help="output file name", required=True)
return parser.parse_args()
def main():
print("Script is starting")
args = parse_args()
doc = PhotoScan.app.document #application class
chunk = doc.addChunk()
# folder location
#path_photos = '\Users\tarunluthra\Downloads\PS_test\'
#path_photos += "\\"
#print(path_photos)
# Specify folder
# path_photos = PhotoScan.app.getExistingDirectory("Specify folder with input photos:")
path_photos = args.inputpath
project_path = args.outputfile
doc.save(project_path)
PhotoScan.app.update()
# Specify project file name
#project_path = PhotoScan.app.getSaveFileName("Specify project filename for saving:")
if not project_path.lower().endswith(".psx"):
project_path += ".psx"
#
image_list = [
os.path.join(path_photos, path)
for path in os.listdir(path_photos)
if path.lower().endswith(("jpg", "jpeg", "tif", "png"))
]
chunk.addPhotos(image_list)
PhotoScan.app.update()
## image quality
# app = PhotoScan.Application()
#doc = PhotoScan.app.document
#chu=doc.chunk
chunk.estimateImageQuality()
for image in chunk.cameras:
if float(image.photo.meta['Image/Quality'])<0.5:
image.enabled = False
print ('DISABLE %s' %(image))
# Update
#PhotoScan.app.update()
# chunk.loadReference(path, "xml") # add gps reference position
# chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.NoPreselection, filter_mask=False,keypoint_limit=40000, tiepoint_limit=0)
# chunk.alignCameras()
#Align photos
# chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection)
# chunk.alignCameras()
# chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)
#Align photos
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection)
chunk.alignCameras()
chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)
chunk.buildModel(surface=PhotoScan.Arbitrary, interpolation=PhotoScan.EnabledInterpolation)
chunk.buildDem(source=PhotoScan.DenseCloudData, interpolation=PhotoScan.EnabledInterpolation)
chunk.buildUV(mapping=PhotoScan.GenericMapping)
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=4096)
chunk.exportDem(project_path[:-4]+'t_rgb.tif', image_format=ps.ImageFormatTIFF, nodata = -99999, write_kml=False, write_world=False)
#format=ps.RasterFormatXYZ, #projection=ps.EPSG:4326,
#][, region][, dx][, dy]
# [, blockw][, blockh][,
chunk.PointCloud.export(project_path[:-4]+'ptcloud.obj', format=obj)
PhotoScan.app.update()
try:
doc.save()
PhotoScan.app.update()
except RuntimeError:
PhotoScan.app.messageBox("Can't save project")
# if not doc.save(project_path):
# # PhotoScan.app.messageBox("Can't save project")
# raise Exception("Cannot save project")
if __name__ == "__main__":
main()
Here's the error
BuildDem: source data = Dense cloud, interpolation = Enabled, resolution = 0
Please save project in PSX format before processing
Traceback (most recent call last):
File "PS_test.py", line 95, in <module>
main()
File "PS_test.py", line 74, in main
chunk.buildDem(source=PhotoScan.DenseCloudData, interpolation=PhotoScan.EnabledInterpolation)
RuntimeError: Empty frame path