1
Python and Java API / Re: Adding Images from list to two Groups
« on: March 15, 2021, 02:11:34 PM »
Hi Alexey,
Thank you for this. It helped a lot.
Kind Regards,
Chris
Thank you for this. It helped a lot.
Kind Regards,
Chris
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.
def generate_point_cloud(input_dir, output_dir, calibration_pathA, calibration_pathB, scale):
print("Script started")
doc = PhotoScan.app.document
doc.save(os.path.join(output_dir, "projectGenerated.psx"))
chunk = doc.addChunk()
chunk.label = "New Chunk"
Distance = scale
#Create a list to store the image paths
image_list = list()
#Read the image paths from the .txt file. Strip off the \n using s.strip()
f = open(input_dir, "r")
image_list = f.readlines()
image_list = map(lambda s: s.strip(), image_list)
print(image_list)
#Create two camera groups within the main chunk. One for the HD images and one for the UHD images
HD = chunk.addCameraGroup()
HD.label = "HD"
UHD = chunk.addCameraGroup()
UHD.label = "UHD"
#print(chunk.camera_groups)
#Create two camera calibration files for each image set
calibs = dict()
calibs["HD"] = PhotoScan.Calibration()
calibs["UHD"] = PhotoScan.Calibration()
calibs["HD"].load(calibrationA, "xml")
calibs["UHD"].load(calibrationB, "xml")
#Create two sensors for the two image sizes
sensors = dict()
sensors["HD"] = chunk.addSensor()
sensors["UHD"] = chunk.addSensor()
sensors["HD"].label = "HD"
sensors["UHD"].label = "UHD"
#Add the photos to the project Chunk
chunk.addPhotos(image_list)
print("no cameras ", len(chunk.cameras))
#Place the UHD images in the UHD group and assign the calibration file for that camera. Assign HD images to HD group
#and assign the camera calibration file for those images.
for camera in chunk.cameras:
if camera.sensor.width == 2048:
camera.group = HD
camera.sensor = sensors["HD"]
elif camera.sensor.width == 4096:
camera.group = UHD
camera.sensor = sensors["UHD"]
for sensor in sensors.keys():
calib = calibs[sensor]
sensors[sensor].width = calib.width
sensors[sensor].height = calib.height
sensors[sensor].type = calib.type
sensors[sensor].user_calib = calib
sensors[sensor].fixed = True
PhotoScan.app.update()
#align photos
chunk.loadReferenceExif(load_rotation=False, load_accuracy=False)
chunk.matchPhotos(accuracy = PhotoScan.HighAccuracy, preselection = PhotoScan.Preselection.GenericPreselection, filter_mask = False, keypoint_limit = 50000)
print("aligning ", len(chunk.cameras), " images")
chunk.alignCameras() # instead of alignPhotos
chunk.buildDenseCloud(quality = PhotoScan.LowQuality, filter = PhotoScan.AggressiveFiltering)
for camera in chunk.cameras:
#if camera.label[0:26] == the camera.label of any of the other camera labels
# sb = chunk.addScalebar(camera, other_camera)
sb.reference.distance = float(Distance)
chunk.updateTransform()
chunk.exportCameras(os.path.join(output_dir, "cameras.xml"))
chunk.exportPoints(path=os.path.join(output_dir, "points.xyz"))
#doc.save(path = project_path)
doc.save(os.path.join(output_dir, "projectGenerated.psx"))
PhotoScan.app.update()
print("Script finished")
return 1