Skip to content

CameraData

Eric Swanson edited this page Nov 16, 2023 · 9 revisions

A CameraData() Python object is created for each calibrated camera being utilized. Each instance of this class requires all camera intrinsic and extrinsic values unique to that device. For cameras that have not yet been calibrated and the intrinsic values are not known, the user is directed to the CalTech Camera Calibration library , or other relevant calibration libraries such as the calibration functions contained in OpenCV. Intrinsic values are accepted in the CIRN convention or in the direct linear transform coefficient notation. See the CoastalImageLib User Manual for detailed information on calibration and intrinsic value formatting. The user can also optionally specify the coordinate system being utilized, with the further option of providing the local origin for a coordinate transform.

class definition

CameraData(intrinsics, extrinsics, origin="None", coords="local", mType="CIRN", nc=1 source

Object that contains camera matrices in homogenous coordinates from camera
extrinsics and intrinsics.Must be re-initialized for each new camera
(dependent on specific camera's intrinsic and extrinsic calibration).

If local coordinates are desired and inputs are not yet converted to local,
user can flag coords = 'geo' and input local origin.

If intrinsics are in a format other than CIRN (currently the only other
supported format is DLT), user can flag mType = 'DLT'.

Arguments:
    intrinsics (list or array): [1 x 11] list of intrinsic values in CIRN
        format or DLT coefficients
    extrinsics (list or array): [1 x 6] list of extrinsic values
        [ x y z azimuth tilt swing] of the camera.
        XYZ should be in the same units as xyz points to be converted.
        Azimith, tilt, and swing should be in radians.
        (azimuth, tilt, and swing should be defined by CIRN convention)
    origin (list or array): local origin, x, y, and angle
    coords (string): tag to indicate if coordinates are in geo or local
    mType (string): tag to indicate if intrinsics are in CIRN or DLT
    nc (int): size of color channel, eg: 1=grayscale, 3=RGB

Attributes (if mType = 'CIRN'): (in local coords)
    P: [3 x 4] transformation matrix to convert XYZ coordinates to
        distorted UV coordinates.
    K: [3 x 3] K matrix to convert XYZ points to distorted UV coordinates
    R: [3 x 3] Rotation matrix to rotate XYZ world coordinates to camera
        coordinates
    IC: [4 x 3] Translation matrix to translate XYZ world coordinates to
        camera coordinates
    Ud: Distorted u pixel coordinates for current XYZ rectification grid.
        (defaults to "None" until user adds via addUV function)
    Vd: Distorted v pixel coordinates for current XYZ rectification grid.
        (defaults to "None" until user adds via addUV function)

Example #m[] is list of intrinsic calibration parameters #ex[] is list of exstrinsic calibration parameters

cams = ['camera1', 'camera2']
cameras = np.empty(len(cams),dtype=object)
for i in range(len(cams)):
    cameras[i] = cf.CameraData(m[i], ex[i], coords = 'local', origin= 'None', mType = 'DLT', nc=3)

Class methods

Methods are listed in alphabetical order.

assignCoeffs

assingCoeffs() source

Assign Coefficients to Intrinsic Matrix. Called within class __init__ method.

addUV

addUV(grid) source

    This function precalculates the distorted UV coordinates (UVd)  that
    correspond to a set of world xyz points for the camera matrix contained
    in the self object. 

    This allows the user to save computational time by only having to do 
    this calculation once for one camera-grid pair.

    Arguments:
        self: CameraData object containing the DLT coefficient vector A->L
        grid (XYZGrid object): XYZGrid object containing real world coords

    Attributes:
        Ud (ndarray): Nx1 vector of distorted U coordinates for N points.
        Vd (ndarray): Nx1 vector of distorted V coordinates for N points.

Example: #m[] is list of intrinsic calibration parameters #ex[] is list of exstrinsic calibration parameters

cams = ['camera1', 'camera2']
cameras = np.empty(len(cams),dtype=object)
for i in range(len(cams)):
    cameras[i] = cf.CameraData(m[i], ex[i], coords = 'local', origin= 'None', mType = 'DLT', nc=3)

#Grid boundaries
xMin = 0
xMax = 500
yMin = -500
yMax = 1200
dy = 1
dx = 1
z = 0

grid = XYZGrid([xMin,xMax], [yMin,yMax], dx, dy, z)

cameras[0].addUV(grid)

getMatrices

getMatrices() source

Part of initializer for mType = 'CIRN'. Called in class __init__ method

Calculates P, K, R, and IC matrices

Returns:
    P: full camera matrix (3x3)
    K: intrinsic matrix (3x3)
    R: rotation matrix (3x3)
    IC: identity translation matrix
        (3x3 identity matrix - 3x1 translation matrix)

localTransformExtrinsics

localTransformExtrinsics() source

Transforms extrinsics in local coordinates to geo, or extrinsics
in geo coordinates to local.

Angle should be defined by CIRN convention.

Called in class __init__ method.

Returns:
    extrinsics_out (dict): Local or geo extrinsics [x,y,z,a,t,r]
        (a = azimuth, t = tilr, r = roll)