Main Content

extrinsicsToCameraPose

(Not recommended) Convert extrinsics to camera pose

extrinsicsToCameraPose is not recommended. Use the extr2pose function instead. For more information, see Version History.

Description

cameraPose = extrinsicsToCameraPose(tform) returns a rigid3d object that contains the camera pose, cameraPose, in world coordinates. tform is a transformation from world coordinates to camera coordinates, specified as a rigid3d object.

[orientation,location] = extrinsicsToCameraPose(rotationMatrix,translationVector) returns 3-D camera pose orientation and location in world coordinates. The inputs, rotationMatrix and translationVector, represent the transformation from world coordinates to camera coordinates.

example

Examples

collapse all

Create a rotation matrix and a translation vector.

rotationMatrix = eye(3);
translationVector = [0 0 -10];

Compute the camera orientation matrix and location vector in world coordinates.

[orientation,location] = extrinsicsToCameraPose(rotationMatrix,translationVector)
orientation = 3×3

     1     0     0
     0     1     0
     0     0     1

location = 1×3

     0     0    10

Compute the camera pose in world coordinates as a rigid 3-D object.

tform = rigid3d(rotationMatrix,translationVector);
cameraPose = extrinsicsToCameraPose(tform)
cameraPose = 
  rigid3d with properties:

       Rotation: [3x3 double]
    Translation: [0 0 10]

Input Arguments

collapse all

Transformation from world coordinates to camera coordinates, specified as a rigid3d object. The transformation allows you to transform points from the world coordinate system to the camera coordinate system.

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

Data Types: double | single

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

Data Types: double | single

Output Arguments

collapse all

Camera pose in world coordinates, returned as a rigid3d object. cameraPose is computed as:

cameraPose.Rotation = tform.Rotation'
cameraPose.Translation = -tform.Translation * tform.Rotation'

3-D orientation of the camera in world coordinates, returned as a 3-by-3 matrix.

The relationship between the rotation matrix and the output orientation matrix is:

orientation = rotationMatrix'

3-D location of the camera in world coordinates, specified as a three-element vector.

The relationship between the translation vector and the output orientation matrix is:

location = –translationVector*rotationMatrix'

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2016b

collapse all

R2022b: Not recommended

Starting in R2022b, most Computer Vision Toolbox™ functions create and perform geometric transformations using the premultiply convention. However, the extrinsicsToCameraPose function uses the postmultiply convention. Although there are no plans to remove extrinsicsToCameraPose at this time, you can streamline your geometric transformation workflows by switching to the extr2pose function, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.

  • Change instances of the function name cameraPoseToExtrinsics to pose2extr.

  • Specify the extrinsics as a rigidtform3d object using the extrinsics argument. extr2pose does not support specifying extrinsics using the rotationMatrix and translationVector input arguments. Note that you create the rigidtform3d object using the transpose of rotationMatrix or the transpose of the transformation matrix in the T property of tform.

Discouraged UsageRecommended Replacement

This example specifies the extrinsics as a rotation matrix rotationMatrix in the premultiply convention and a translation vector translationVector, then converts the extrinsics to a camera pose using the extrinsicsToCameraPose function, using the transpose of rotationMatrix.

rotationMatrix = eye(3);
translationVector = [0 0 -10];
[orientationOld,location] = ...
    extrinsicsToCameraPose(rotationMatrix',translationVector)

This example specifies extrinsics as a rigidtform3d object, then converts the extrinsics to a camera pose using the extr2pose function.

rotationMatrix = eye(3);
translationVector = [0 0 -10];
extrinsics = rigidtform3d(orientation,location);
cameraPose = extr2pose(extrinsics);

If you need to obtain the camera orientation and location, then you can query properties of cameraPose.

orientation = cameraPose.R;
location = cameraPose.Translation;

If you want the orientation in the postmultiply convention, take the transpose of cameraPose.R.

orientationOld = cameraPose.R;

This example specifies extrinsics as a rigid3d object using the transpose of the geometric transformation matrix T in the premultiply convention, then converts the extrinsics to a camera pose using the extrinsicsToCameraPose function.

A = [1 0 0 0; 0 1 0 0; 0 0 1 -10; 0 0 0 1];
extrinsicsOld = rigid3d(A');
cameraPoseOld = extrinsicsToCameraPose(extrinsicsOld);

This example specifies extrinsics as a rigidtform3d object using the geometric transformation matrix T, then converts the extrinsics to a camera pose using the extr2pose function.

A = [1 0 0 0; 0 1 0 0; 0 0 1 -10; 0 0 0 1];
extrinsics = rigidtform3d(A);
cameraPose = extr2pose(extrinsics);

If instead you start with an existing rigid3d object extrinsicsOld, then you can get the geometric transformation matrix in the postmultiply convention by querying the property T of extrinsicsOld.

T = extrinsicsOld.T;
extrinsics = rigidtform3d(T');
cameraPose = extr2pose(extrinsics);