Forum

Author Topic: Getting separate calibrations for each camera  (Read 8798 times)

shirofukurou

  • Newbie
  • *
  • Posts: 6
    • View Profile
Getting separate calibrations for each camera
« on: July 17, 2015, 07:53:02 PM »
I have a series of images in a series of folders. Each folder is a separate camera, and each camera requires a separate calibration, and the images are taken at separate time points. The following script loads up the images and reconstructs the 3D scene at the different time points. What it doesn't do is produce a separate calibration per camera. I was hoping that the putting each camera into a different group would achieve this but actually it doesn't look like my code does that. As far as I can see from the output, all the cameras end up in in the same group. Obviously I'm missing something. I've put the part I think might be wrong in red.

Any help appreciated!
Bill

import os
import PhotoScan

doc = PhotoScan.app.document

input_folder = '/Users/wis/Work/data/2014-10-08/test_frames/clip0000'
output_folder = '/Users/wis/Work/data/2014-10-08/test/clip0000'
camera_folders = ['camera00','camera01','camera02','camera03','camera04']
folders = list()
for f in camera_folders:
    folders.append(os.path.join(input_folder, f))

#processing parameters
accuracy = PhotoScan.Accuracy.HighAccuracy  #align photos accuracy
preselection = PhotoScan.Preselection.GenericPreselection
keypoints = 40000 #align photos key point limit
tiepoints = 10000 #align photos tie point limit
source = PhotoScan.PointsSource.DensePoints #build mesh source
surface = PhotoScan.SurfaceType.Arbitrary #build mesh surface type
quality = PhotoScan.Quality.MediumQuality #build dense cloud quality
filtering = PhotoScan.FilterMode.AggressiveFiltering #depth filtering

print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = "New Chunk"

#loading images
photo_list = list()
for f in folders:
    image_list = os.listdir(f)
    photo_list.append(os.path.join(f, image_list[0]))
chunk.addPhotos(photo_list)

# put the new cameras into different camera groups
for camera in chunk.cameras:
    cameraGroup = chunk.addCameraGroup()
    camera.group = cameraGroup


# load in the extra frames per camera
for iframe in range(1, 6):
    frame = chunk.addFrame()
    photo_list = list()
    for ifolder in range(0, len(folders)):
        image_list = os.listdir(folders[ifolder])
        frame.cameras[ifolder].open(os.path.join(folders[ifolder], image_list[iframe]))

#align photos
for frame in chunk.frames:
    frame.matchPhotos(accuracy=accuracy,preselection=preselection,filter_mask=False,keypoint_limit=keypoints,tiepoint_limit=tiepoints)
chunk.alignCameras()
chunk.optimizeCameras()

#building dense cloud
for frame in chunk.frames:
    frame.buildDenseCloud(quality = quality, filter = filtering)

# and save
doc.save(os.path.join(output_folder, 'PhotoScanModel.psz'))



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Getting separate calibrations for each camera
« Reply #1 on: July 17, 2015, 09:42:11 PM »
Hello,

camera.group is just a folder in the Workspace pane, to use different calibration groups you need to introduce sensor instance and assign separate sensor for each camera.

In the neighboring thread there's a sample, how it could be done:
http://www.agisoft.com/forum/index.php?topic=4058.msg20958#msg20958
Best regards,
Alexey Pasumansky,
Agisoft LLC

shirofukurou

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Getting separate calibrations for each camera
« Reply #2 on: July 18, 2015, 04:50:45 PM »
Thanks! I'll give that a go. I wanted a bit more control over the sensor instance anyway so it will probably be useful to add it explicitly.

Cheers
Bill

shirofukurou

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Getting separate calibrations for each camera
« Reply #3 on: July 20, 2015, 05:03:44 PM »
That worked perfectly. Here is the complete working code example for reading in multiple frames and producing multiple calibrated cameras.

Cheers
Bill

Code: [Select]
import os
import PhotoScan

doc = PhotoScan.app.document

input_folder = '/test_input/clip0000'
output_folder = '/test_output/clip0000'
camera_folders = ['camera00','camera01','camera02','camera03','camera04']

#processing parameters
accuracy = PhotoScan.Accuracy.HighAccuracy  #align photos accuracy
preselection = PhotoScan.Preselection.GenericPreselection
keypoints = 40000 #align photos key point limit
tiepoints = 10000 #align photos tie point limit
source = PhotoScan.PointsSource.DensePoints #build mesh source
surface = PhotoScan.SurfaceType.Arbitrary #build mesh surface type
quality = PhotoScan.Quality.MediumQuality #build dense cloud quality
filtering = PhotoScan.FilterMode.AggressiveFiltering #depth filtering

print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = "New Chunk"

#loading images
image_lists = {}
for icamera in range(0, len(camera_folders)):
    # store the full list in the dictionary
    image_list = os.listdir(os.path.join(input_folder, camera_folders[icamera]))
    image_lists[camera_folders[icamera]] = image_list
   
    # create the camera
    camera = chunk.addCamera() # loading photo to the camera instance
    camera.label = camera_folders[icamera]
    camera.open(os.path.join(input_folder, camera_folders[icamera], image_list[0]))
   
    # add the sensor to the camera
    sensor = chunk.addSensor() #creating camera calibration group for the loaded image
    sensor.label = "Calibration Group %02d" % (icamera)
    sensor.type = PhotoScan.Sensor.Type.Frame
    sensor.width = camera.photo.image().width
    sensor.height = camera.photo.image().height
    camera.sensor = sensor


# load in the extra frames per camera
for iframe in range(1, 6):
    frame = chunk.addFrame()
    for icamera in range(0, len(camera_folders)):
        image_list = image_lists[camera_folders[icamera]]
        frame.cameras[icamera].open(os.path.join(input_folder, camera_folders[icamera], image_list[iframe]))

#align photos
for frame in chunk.frames:
    frame.matchPhotos(accuracy = accuracy, preselection = preselection, filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()
chunk.optimizeCameras()

#building dense cloud
iframe = 0
for frame in chunk.frames:
    frame.buildDenseCloud(quality = quality, filter = filtering)
    iframe = iframe + 1


# and save
doc.save(os.path.join(output_folder, 'PhotoScanModel.psz'))