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 3-D rotation matrix and the 3-D translation vector to allow you to transform points from the world coordinate to the camera coordinate system.

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.7824  725.5824

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 that the points are coplanar with z=0. In this case, the number of points, 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 — 3-D rotation3-by-3 matrix

3-D rotation, returned as a 3-by-3 matrix. The rotation matrix together with the translation vector allows you to transform points from the world coordinate to the camera coordinate system..

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 — 3-D translation3-D translation. returned as a 1-by-3 vector. The rotation matrix together with the translation vector allows you to transform points from the world coordinate to the camera coordinate system.

3-D translation, 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 uses two different algorithms to compute the extrinsics depending on whether worldPoints are specified as an M-by-2 or an M-by-3 matrix. The algorithm for the M-by-3 case requires the points to be non-coplanar. It will produce incorrect results if the worldPoints are coplanar. Use an M-by-2 matrix for coplanar points where z= 0.

The extrinsics function computes the rotation matrix and translation vector for a single image in closed form. 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?