Main Content

cameraPoseToExtrinsics

(Not recommended) Convert camera pose to extrinsics

cameraPoseToExtrinsics is not recommended. Use the pose2extr function instead. For more information, see Compatibility Considerations.

Description

tform = cameraPoseToExtrinsics(cameraPose) returns a rigid3d object that contains the transformation from world coordinates to camera coordinates. cameraPose is the orientation and location of the camera in world coordinates, specified as a rigid3d object.

example

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

Examples

collapse all

Create the 3-D orientation matrix and the location vector.

orientation = eye(3);
location = [0 0 10];

Compute the rotation matrix and translation vector to transform points from world coordinates to camera coordinates.

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

     1     0     0
     0     1     0
     0     0     1

translationVector = 1×3

     0     0   -10

Compute the transformation from world coordinates to camera coordinates as a rigid 3-D object.

cameraPose = rigid3d(orientation,location);
tform = cameraPoseToExtrinsics(cameraPose)
tform = 
  rigid3d with properties:

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

Input Arguments

collapse all

Orientation and location of the camera in world coordinates, specified as a rigid3d object.

3-D orientation of the camera in world coordinates, specified as a 3-by-3 matrix. The orientation and location inputs must be the same data type.

Data Types: double | single

3-D location of the camera in world coordinates, specified as a three-element vector. The orientation and location inputs must be the same data type.

Data Types: double | single

Output Arguments

collapse all

Transformation from world coordinates to camera coordinates, returned as a rigid3d object. The transformation allows you to transform points from the world coordinate system to the camera coordinate system. tform is computed as:

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

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 system to the camera coordinate system.

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

rotationMatrix = orientation'

3-D translation, returned 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.

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

translationVector = –location*orientation'

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 cameraPoseToExtrinsics function uses the postmultiply convention. Although there are no plans to remove cameraPoseToExtrinsics at this time, you can streamline your geometric transformation workflows by switching to the pose2extr function, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.

To update your code:

  • Change instances of the function name cameraPoseToExtrinsics to pose2extr.

  • Specify the camera pose as a rigidtform3d object using the cameraPose argument. pose2extr does not support specifying the camera pose using the orientation and translation input arguments. Note that you create the rigidtform3d object using the transpose of orientation or the transpose of the transformation matrix in the T property of tform.

Discouraged UsageRecommended Replacement

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

orientation = eye(3);
location = [0 0 10];
[rotationMatrixOld,translationVector] = cameraPoseToExtrinsics( ...
    orientation',location)

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

orientation = eye(3);
location = [0 0 10];
cameraPose = rigidtform3d(orientation,location);
extrinsics = pose2extr(cameraPose);

If you need to obtain a rotation matrix and translation vector, then you can query properties of extrinsics.

rotationMatrix = extrinsics.R;
translationVector = extrinsics.Translation;

If you want the rotation matrix in the postmultiply convention, take the transpose of extrinsics.R.

rotationMatrixOld = extrinsics.R';

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

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

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

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

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

T = cameraPoseOld.T;
cameraPose = rigidtform3d(T');
extrinsics = pose2extr(cameraPose);