Forum

Author Topic: Trouble converting to 1.1 python API  (Read 3475 times)

shirofukurou

  • Newbie
  • *
  • Posts: 6
    • View Profile
Trouble converting to 1.1 python API
« on: January 29, 2015, 02:59:44 PM »
Sad to say I'm having terrible trouble getting my python script working in the new 1.1 API. I'm using multiple frames per camera and this is what I had that was working nicely in 1.0.4


    initial_calibration = PhotoScan.Calibration()
    initial_calibration.fx = pixel_focal_length
    initial_calibration.fy = pixel_focal_length

    #Loading images:           
    for iframe in range(0, nframes):

        for icamera in range(0, ncameras):
            if iframe == 0:
                chunk.cameras.add(os.path.join(input_folder, folders[icamera], image_folders[icamera][iframe]))
                chunk.cameras[icamera].user_calib = initial_calibration
                chunk.cameras[icamera].label = folders[icamera]
            else:
                f = PhotoScan.Frame()
                f.open(os.path.join(input_folder, folders[icamera], image_folders[icamera][iframe]), 0)
                chunk.cameras[icamera].frames.append(f)
    doc.activeChunk = chunk
           
    print('matchPhotos')
    chunk.matchPhotos(accuracy='high', preselection='disabled', filter_mask=False, point_limit=100000)
    print('alignPhotos')
    chunk.alignPhotos()


I can change the cameras.add to addCamera easily enough but then the user_calib doesn't work. When I try and access the sensor element on the new camera, it tells me that it doesn't exist. If I just skip the user_calib stage it then fails on the frames. I can convert PhotoScan.Frame() to chunk.addFrame() but that doesn't associate the frame with the camera and actually doesn't seem to create a Frame object anyway. According to the documentation Frame has been removed but it doesn't tell me what it has been replaced with and there are still plenty of references to frames...

Any help appreciated. For now I've gone back to 1.0.4 but I would like to use the new API. It looks a lot cleaner and there are some nice new features in 1.1.

Cheers
Bill

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14935
    • View Profile
Re: Trouble converting to 1.1 python API
« Reply #1 on: January 29, 2015, 03:10:27 PM »
Hello Bill,

All calibration information is now stored in chunk.sensors. So you can acces to the calibration group corresponding to the camera via camera.sensor.calibration or camera.sensor.user_calib.

However, when using .addCamera() function please check that sensor instance is properly generated in chunk and assigned to the camera. Alternatively you can use chunk.addPhotos([list_of_paths]) function, in this case sensor instances will be automatically generated and you can then add new frame and load the images for for each camera.

From another major changes: note that instead of doc.activeChunk you should now use doc.chunk. And most of the string arguments in the processing functions have been changed to eNum instances. So your line for matching should look as following:
Code: [Select]
chunk.matchPhotos(accuracy = PhotoScan.Accuracy.HighAccuracy, preselection = PhotoScan.Preselection.NoPreselection, filter_mask = False, keypoint_limit = 100000, tiepoint_limit = 0)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14935
    • View Profile
Re: Trouble converting to 1.1 python API
« Reply #2 on: January 29, 2015, 03:12:07 PM »
When you are using chunk.addFrame() function new frame is created for each camera in the chunk, but you'll need to load new images for this newly added frame for each camera.
Best regards,
Alexey Pasumansky,
Agisoft LLC