Forum

Author Topic: Loading camera extrinsics and intrinsics  (Read 3950 times)

cyclo

  • Newbie
  • *
  • Posts: 3
    • View Profile
Loading camera extrinsics and intrinsics
« on: July 10, 2018, 03:38:55 PM »
Hi,

I'm trying to import camera's of which I know the location and orientation.

My camera calibration file "extrinsics.txt" contains X,Y,Z and Pitch,Yaw,Roll and looks like this:

Quote
160865296_0_0.png   202228   503600   1620.77   -4.71239e-05   -0.000553269   1.57166
160965118_0_0.png   202233   502477   1618.94   0.000794125   0.000572468   4.70667
160865298_0_0.png   202651   503600   1621.07   0.000101229   -0.00047473   1.57178
160965116_0_0.png   202657   502474   1618.79   0.00010821   0.000572468   4.70528
160865300_0_0.png   203067   503601   1620.81   0.000277507   -0.000298451   1.57371
160965114_0_0.png   203074   502472   1618.99   -0.000699877   0.000486947   4.70772


Per camera I have a calibration file like this:

Quote
<?xml version="1.0" encoding="UTF-8"?>
<calibration>
   <projection>frame</projection>
   <width>17310</width>
   <height>11310</height>
   <f>16750</f>
   <cx>8655</cx>
   <cy>5625</cy>
</calibration>


I Try to combine this information with the following script:
Code: [Select]
import os
import PhotoScan
from glob import glob

# 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"

# new project
doc = PhotoScan.app.document

# new chunk
chunk = doc.addChunk()

# load extrinsics
# label used in file is equal to img_path
chunk.loadReference( ext_path )

# load images and intrinsics
img_list = os.listdir( img_dir )
int_list = os.listdir( int_dir )
for img_path, int_path in zip( img_list, int_list ):

# load image
# camera = chunk.AddCamera()
camera = chunk.addCamera()
camera.open( os.path.join( img_dir, img_path ) )

# link extrinsics to image by making the label equal
camera.label = img_path

# load intrinsics
calibration = PhotoScan.Calibration()
calibration.load( os.path.join( int_dir, int_path ) )
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

# now that we loaded all data,
# start processing
chunk.matchPhotos( accuracy=PhotoScan.HighAccuracy, generic_preselection=True, reference_preselection=False )
#chunk.alignCameras()
#chunk.optimizeCameras()
#chunk.buildDepthMaps( quality = PhotoScan.LowQuality, filter = PhotoScan.AggressiveFiltering )
#chunk.buildDenseCloud( point_colors = True )

# now that we're done processing,
# store the results
doc.save( out_path )


However, this results in an image size mismatch error.
Am I approaching this in the correct way?
What does the image size mismatch mean?
All my images have the same size.

Any help is much appreciated.

cyclo

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Loading camera extrinsics and intrinsics
« Reply #1 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:

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.