Camera models

Camera models are implemented as sub-classes of Camera in the camera module. Each source image requires its own camera model instance. Models can be created from supported file formats with a camera factory. Camera factories are implemented as sub-classes of Cameras in the factory module.

Frame cameras

Factory creation

The FrameCameras factory creates FrameCamera models, from interior and exterior parameter files:

import orthority as oty

# URLs of required files
url_root = 'https://raw.githubusercontent.com/leftfield-geospatial/orthority/main/tests/data/'
src_file = url_root + 'ngi/3324c_2015_1004_05_0182_RGB.tif'  # NGI aerial image
int_param_file = url_root + 'io/ngi_int_param.yaml'  # Orthority format interior parameters
ext_param_file = url_root + 'io/ngi_xyz_opk.csv'  # CSV format exterior parameters

# create camera for src_file
cameras = oty.FrameCameras(int_param_file, ext_param_file)
camera = cameras.get(src_file)

The factory can also be created from image EXIF / XMP tags:

src_file = url_root + 'odm/images/100_0005_0140.tif'  # drone image with EXIF / XMP tags

cameras = oty.FrameCameras.from_images([src_file])
camera = cameras.get(src_file)

World / ortho CRS

FrameCameras will read or choose a world / ortho CRS from these exterior parameter formats:

The world / ortho CRS is available via the crs attribute:

cameras = oty.FrameCameras.from_images([src_file])
print(cameras.crs)
# EPSG:32651

An explicit world / ortho CRS can be specified with io_kwargs as explained in the next section.

Parameter IO

Internally, camera factories use the param_io module to read and interpret parameter files.

The io_kwargs argument can be used in FrameCameras or from_images() to pass keyword arguments to the FrameReader sub-class corresponding to the exterior parameter file format.

E.g. to create a factory from image EXIF / XMP tags and pass an explicit world / ortho CRS to ExifReader:

io_kwargs = dict(crs='EPSG:32751')
cameras = oty.FrameCameras.from_images([src_file], io_kwargs=io_kwargs)

print(cameras.crs)
# EPSG:32751

Camera options

The cam_kwargs argument can be used in FrameCameras or from_images() to pass keyword arguments to the FrameCamera class. E.g. to pass the distort and alpha arguments:

cam_kwargs = dict(distort=False, alpha=0.0)
cameras = oty.FrameCameras.from_images([src_file], cam_kwargs=cam_kwargs)
camera = cameras.get(src_file)

print(camera.distort)
print(camera.alpha)
# False
# 0.0

Model export

Camera model parameters can be exported to Orthority format interior and exterior parameter files with write_param():

cameras = oty.FrameCameras.from_images([src_file])
cameras.write_param('.')

RPC cameras

Factory creation

The RpcCameras factory creates RpcCamera models from an Orthority RPC parameter file:

import orthority as oty

# URLs of required files
url_root = 'https://raw.githubusercontent.com/leftfield-geospatial/orthority/main/tests/data/'
src_file = url_root + 'rpc/qb2_basic1b.tif'  # satellite image with RPC tags
rpc_param_file = url_root + 'rpc/rpc_param.yaml'  # Orthority format RPC parameters

# create camera for src_file
cameras = oty.RpcCameras(rpc_param_file)
camera = cameras.get(src_file)

Camera models can also be created from image RPC tags / sidecar files:

cameras = oty.RpcCameras.from_images([src_file])
camera = cameras.get(src_file)

Parameter IO

Internally, the read_im_rpc_param() function is used to read image RPC tags / sidecar files. The io_kwargs argument can be used in from_images() to pass keyword arguments to read_im_rpc_param().

E.g. to display a progress bar while reading image RPC tags / sidecar files:

io_kwargs = dict(progress=True)
cameras = oty.RpcCameras.from_images([src_file], io_kwargs=io_kwargs)

Camera options

The cam_kwargs argument can be used in RpcCameras or from_images() to pass keyword arguments to RpcCamera. E.g. to specify a world / ortho crs:

cam_kwargs = dict(crs='EPSG:32735')
cameras = oty.RpcCameras.from_images([src_file], cam_kwargs=cam_kwargs)
camera = cameras.get(src_file)

print(camera.crs)
# EPSG:32735

Model refinement

RPC models can be refined with GCPs using the refine() method. GCPs can be read from an Orthority GCPs file:

gcps_file = url_root + 'rpc/gcps.geojson'  # Orthority format GCPs
cameras = oty.RpcCameras.from_images([src_file])
cameras.refine(gcps_file)
camera = cameras.get(src_file)  # refined camera model

Or GCPs can be read from image tags:

cameras = oty.RpcCameras.from_images([src_file])
cameras.refine([src_file])
camera = cameras.get(src_file)  # refined camera model

The read_im_gcps() function is used internally to read GCPs from image tags. io_kwargs can be used in refine() to pass keyword arguments to read_im_gcps() when GCPs are supplied in image tags:

io_kwargs = dict(progress=True)  # show a progress bar
cameras = oty.RpcCameras.from_images([src_file])
cameras.refine([src_file], io_kwargs=io_kwargs)

The refine_rpc() function is used internally to perform RPC refinement. fit_kwargs can be used in refine() to pass keyword arguments to refine_rpc():

fit_kwargs = dict(method=oty.RpcRefine.shift)  # use 'shift' refinement method
cameras = oty.RpcCameras.from_images([src_file])
cameras.refine([src_file], fit_kwargs=fit_kwargs)

Model export

Camera model parameters can be exported to an Orthority RPC parameter file with write_param():

cameras = oty.RpcCameras.from_images([src_file])
cameras.write_param('.')

When the models have been refined, write_param() exports the refined models together with the GCPs used to refine them. GCPs are written to an Orthority GCPs file:

cameras = oty.RpcCameras.from_images([src_file])
cameras.refine([src_file])
cameras.write_param('.')