1
Python and Java API / Re: Loading camera extrinsics and intrinsics
« on: July 11, 2018, 10:24:05 AM »
An update:
It seems that loading the images first using chunk.addPhotos resolves the image size mismatch.
I am now using the following script:
However, the chunk now contains 12 camers.
6 of which are just the image names, which also contain the correct image and reference data.
The other 6 contain the full image paths, but don't actually show the image or any reference data.
After camera alignment only the first 6 cameras are aligned.
This seems to be fine, although I'm slightly confused by the 6 invalid cameras.
It seems that loading the images first using chunk.addPhotos resolves the image size mismatch.
I am now using the following script:
Code: [Select]
import os
import PhotoScan
# settings for this project
ext_path = "camera_extrinsics/extrinsics.txt"
img_dir = "images_no_subs/"
int_dir = "camera_intrinsics/"
out_path = "photoscan_out/project.psx"
def get_files_in_directory( directory ):
full_file_paths = list()
file_names = os.listdir( directory )
for file_name in file_names:
full_file_paths.append( os.path.join( directory, file_name ) )
return full_file_paths
# new project and chunk
doc = PhotoScan.app.document
chunk = doc.addChunk()
# list images and intrinsics
full_img_paths = get_files_in_directory( img_dir )
full_int_paths = get_files_in_directory( int_dir )
# load photos
chunk.addPhotos( full_img_paths )
# load images and intrinsics
for img_path, int_path in zip( full_img_paths, full_int_paths ):
# load image
camera = chunk.addCamera()
#camera.open( img_path )
# link extrinsics to image by making the label equal
camera.label = img_path
# load intrinsics
calibration = PhotoScan.Calibration()
calibration.load( int_path )
# add intrinsics calibration to sensor
sensor = chunk.addSensor()
sensor.user_calib = calibration
# link intrinsics to image by setting label equal (perhaps not necessary?)
sensor.label = img_path
# link intrinsics to image by assigning to camera
camera.sensor = sensor
# load extrinsics
# label used in file is equal to img_path
chunk.loadReference( ext_path )
However, the chunk now contains 12 camers.
6 of which are just the image names, which also contain the correct image and reference data.
The other 6 contain the full image paths, but don't actually show the image or any reference data.
After camera alignment only the first 6 cameras are aligned.
This seems to be fine, although I'm slightly confused by the 6 invalid cameras.