Documentation

extrinsics

Compute location of calibrated camera

Syntax

  • [rotationMatrix,translationVector] = extrinsics(imagePoints,worldPoints,cameraParams) example

Description

example

[rotationMatrix,translationVector] = extrinsics(imagePoints,worldPoints,cameraParams) returns the translation and rotation of the camera, relative to the world coordinate system defined by worldPoints.

Code Generation Support:
Supports Code Generation: Yes
Supports MATLAB Function block: No
Code Generation Support, Usage Notes, and Limitations

Examples

collapse all

Compute Extrinsics

Load calibration images.

numImages = 9;
files = cell(1, numImages);
 for i = 1:numImages
    files{i} = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'calibration', 'slr', sprintf('image%d.jpg', i));
 end

Detect the checkerboard corners in the images.

[imagePoints, boardSize] = detectCheckerboardPoints(files);

Generate the world coordinates of the checkerboard corners in the pattern-centric coordinate system, with the upper-left corner at (0,0).

squareSize = 29; % in millimeters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

Calibrate the camera.

cameraParams = estimateCameraParameters(imagePoints, worldPoints);

Load image at new location.

imOrig = imread(fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'calibration', 'slr', 'image9.jpg'));
figure; imshow(imOrig);
title('Input Image');

Undistort image.

im = undistortImage(imOrig, cameraParams);

Find reference object in new image.

[imagePoints, boardSize] = detectCheckerboardPoints(im);

Compute new extrinsics.

[rotationMatrix, translationVector] = extrinsics(imagePoints, worldPoints, cameraParams)
rotationMatrix =

    0.1417   -0.7409    0.6565
    0.9661   -0.0410   -0.2548
    0.2157    0.6703    0.7100


translationVector =

  -29.2584   35.7827  725.5826

Related Examples

Input Arguments

collapse all

imagePoints — Image coordinates of pointsM-by-2 array

Image coordinates of points, specified as an M-by-2 array. The array contains M number of [x, y] coordinates. The imagePoints and worldPoints inputs must both be double or both be single.

Data Types: single | double

worldPoints — World coordinates corresponding to image coordinatesM-by-2 matrix | M-by-3 matrix

World coordinates corresponding to image coordinates, specified as an M-by-2 or an M-by-3 matrix. The imagePoints and worldPoints inputs must both be double or both be single.

When you specify an M-by-2 matrix of [x, y] coordinates, the function assumes z to be 0. In this case, if worldPoints are co-planar, then the number of coordinates, M, must be greater than 3.

When you specify an M-by-3 matrix of [x, y, z] coordinates, then M, must be greater than 5.

Data Types: single | double

cameraParams — Object for storing camera parameterscameraParameters object

Object for storing camera parameters, specified as a cameraParameters returned by the estimateCameraParameters function or the Camera Calibrator app. This object contains the intrinsic, extrinsic, and lens distortion parameters of a camera.

Output Arguments

collapse all

rotationMatrix — Rotation of camera3-by-3 matrix

Rotation of camera, returned as a 3-by-3 matrix.

If you set the imagePoints and worldPoints inputs to class double, then the function returns the rotationMatrix and translationVector as double. Otherwise, they are single.

translationVector — Translation of camera1-by-3 vector describing translation of the camera

Translation of camera, returned as a 1-by-3 vector.

If you set the imagePoints and worldPoints inputs to class double, then the function returns the rotationMatrix and translationVector as double. Otherwise, they are single.

More About

collapse all

Algorithms

The extrinsics function computes the rotation matrix and translation vector for a single image in closed form using a homography between world points and image points, and camera intrinsics. During calibration, the extrinsics are estimated numerically to minimize the reprojection errors for all calibration images. Therefore, using the extrinsics function on one of the calibration images returns rotation matrix and translation vector slightly different from the ones obtained during calibration.

Introduced in R2014a

Was this topic helpful?