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.


Topics - Chris_1979

Pages: [1]
1
Python and Java API / Adding Images from list to two Groups
« on: March 12, 2021, 01:51:02 PM »
Hi There,

I have been using the attached script with Metashape version 1.5.5 for the past couple of years. I recently updated to 1.7.1 and the script no longer works. I think I fixed one issue with the the way I was loading the XML calibration file, but I think it's now failing on the chunk.addPhotos(image_list).

Do I need to add the extra arguments (filegroup, and image layout)? If so, how should I do that?

Kind Regards,
Chris

2
Hi,

I know there have been similar questions to this one asked previously, but I'm struggling to apply those solutions here.

I have a script which places images in to two separate groups based on the image resolution. Now I want to compare part of the camera.label of the images in these two groups and if there's a match I'll apply a scalebar between the two cameras.

The script is working, apart from the section which compares the camera.label of the images in the two groups.

Any help would be greatly appreciated.

Thanks

Code: [Select]
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

Pages: [1]