Hi,
I have written a python script to process a 3D model, my initial tests have shown that it takes about 1 hours to generate a 3D model of 120 photos with High (alignment) and medium (depth cloud) accuracy. However, if I ramp up the resolution bar the processing time took about 8 hours. Is there a way that I can speed up the 3D model process? I have read about split in chunks script can help out in doing something similar...can you please help out on how I can implement the script running in headless mode on a server to do this processing? I have attached my script in this post.
thanks,
Tarun
#PhotoScan.app.enumGPUDevices()
import PhotoScan
import os
import argparse
import time
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.inputpath + args.outputfile
# project_path = args.outputfile
if not project_path.lower().endswith(".PSX"):
project_path += ".PSX"
doc.save(project_path)
print(path_photos)
print(project_path)
#doc.save(project_path)
chunk = doc.addChunk()
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"
# doc.save(project_path)
chunk = doc.addChunk()
#
image_list = [
os.path.join(path_photos, path)
for path in os.listdir(path_photos)
if path.lower().endswith(("jpg", "jpeg", "png"))
]
chunk.addPhotos(image_list)
PhotoScan.app.update()
print(len(image_list))
print(chunk.cameras)
wgs84 = PhotoScan.CoordinateSystem("EPSG::4326")
chunk.crs = wgs84
## 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(adaptive_fitting = False)
# chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)
# chunk.buildModel(surface=PhotoScan.Arbitrary, interpolation=PhotoScan.EnabledInterpolation)
# doc.save()
# 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=PhotoScan.ImageFormatTIFF, nodata = -99999, write_kml=False, write_world=False)
# chunk.exportPoints(project_path[:-4]+'ptcloud.obj', format=PhotoScan.PointsFormatOBJ)
chunk.matchPhotos(accuracy=PhotoScan.HighestAccuracy, preselection=PhotoScan.GenericPreselection)
chunk.alignCameras(adaptive_fitting = False)
chunk.buildDenseCloud(quality=PhotoScan.UltraQuality)
doc.save()
chunk.buildDem(source=PhotoScan.DenseCloudData, interpolation=PhotoScan.EnabledInterpolation)
doc.save()
chunk.buildModel(surface=PhotoScan.Arbitrary, interpolation=PhotoScan.EnabledInterpolation)
chunk.buildUV(mapping=PhotoScan.GenericMapping)
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=4096)
doc.save()
chunk.exportDem(project_path[:-4]+'t_rgb.tif', image_format=PhotoScan.ImageFormatTIFF, nodata = -99999, write_kml=False, write_world=False)
chunk.exportPoints(project_path[:-4]+'ptcloud.obj', format=PhotoScan.PointsFormatOBJ)
# chunk.exportPoints()
#format=ps.RasterFormatXYZ, #projection=ps.EPSG:4326,
#][, region][, dx][, dy]
# [, blockw][, blockh][,
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__":
t0 = time.time()
main()
t1 = time.time()
total = t1 - t0
print("total time =", total, "seconds")