F_VN_CalibrateCamera

F_VN_CalibrateCamera 1:

Compute the camera parameters (intrinsic + extrinsic) by evaluating an image containing a calibration pattern (circles).
Can use available TwinCAT Job Tasks for executing parallel code regions.

Syntax

Definition:

FUNCTION F_VN_CalibrateCamera : HRESULT
VAR_INPUT
    ipSrcImage              : ITcVnImage;
    ipReferencePoints       : ITcVnContainer;
END_VAR
VAR_IN_OUT
    aCameraMatrix           : TcVnMatrix3x3_LREAL;
    aDistortionCoefficients : TcVnArray8_LREAL;
    aRotationMatrix         : TcVnMatrix3x3_LREAL;
    aTranslationVector      : TcVnVector3_LREAL;
    fReprojError            : LREAL;
    stBlobDetectionParams   : TcVnParamsBlobDetection;
    stCalibrationOptions    : TcVnCameraCalibrationOptions;
END_VAR
VAR_INPUT
    hrPrev                  : HRESULT;
END_VAR

F_VN_CalibrateCamera 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image containing a calibration pattern (1 channel, USINT elements)

ipReferencePoints

ITcVnContainer

Reference calibration pattern point positions (ContainerType_Vector_TcVnPoint3_REAL)

hrPrev

HRESULT

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_CalibrateCamera 3: In/Outputs

Name

Type

Description

aCameraMatrix

TcVnMatrix3x3_LREAL

Returns the camera matrix

aDistortionCoefficients

TcVnArray8_LREAL

Returns the lens distortion coefficients [k1, k2, p1, p2, k3, k4, k5, k6]

aRotationMatrix

TcVnMatrix3x3_LREAL

Returns the rotation matrix

aTranslationVector

TcVnVector3_LREAL

Returns the translation vector

fReprojError

LREAL

Returns the reprojection error

stBlobDetectionParams

TcVnParamsBlobDetection

Parameters for the internally used F_VN_DetectBlobs function

stCalibrationOptions

TcVnCameraCalibrationOptions

Calibration options

F_VN_CalibrateCamera 4: Return value

HRESULT

Further information

The function F_VN_CalibrateCamera calculates the intrinsic and extrinsic camera parameters on the basis of an input image containing a calibration pattern. The elements of the calibration pattern must be detectable as a blob.

Input image

The input image ipSrcImage must be a 1-channel grayscale image with a bit depth of 8 bits. This image must contain a calibration pattern with circles that matches the reference points ipReferencePoints. The function expects black filled circles on a white background. To invert the image, the ETcVnThresholdType = TCVN_TT_BINARY_INV of the Blob function can be used.

The expert version F_VN_CalibrateCameraExp is required for a calibration with several input images.

Reference points

The container ipReferencePoints must contain the reference points that are illustrated on the input image ipSrcImage as the calibration pattern. The points must be specified as 3-dimensional points of the type REAL so that the container is of the type ContainerType_Vector_TcVnPoint3_REAL.

The reference points can be generated as follows:

Matrices of the camera parameters

These matrices return the calculated parameters of the camera model. They can then be used for the compensation of the objective distortions and for the conversion between pixel coordinates and world coordinates.

  • Camera matrix
  • Distortion coefficients
  • Rotation matrix
  • Translation vector
F_VN_CalibrateCamera 5:

Rounding errors

On account of rounding errors, the calculated parameter values can deviate slightly from the values calculated in the calibration assistants.

Reprojection errors

Parameters for blob detection

F_VN_CalibrateCamera 6:

No chessboard pattern

As the reference points are detected as a blob structure, the use of chessboard patterns is not possible.

Options for calibration

F_VN_CalibrateCamera 7:

Default settings

To get the default settings from the calibration wizard, the bits bFixAspectRatio, bFixPrincipalPoint, bFixK5, bFixK6 and bRationalModel must be set to TRUE.

bFixPrincipalPoint = „Fix Center Point“

The bit bFixPrincipalPoint corresponds to the option "Fix Center Point" in the camera calibration assistant.

Samples

Required License

TC3 Vision Metrology 2D

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision