Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**MathWorks Machine Translation**

The automated translation of this page is provided by a general purpose third party translator tool.

MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Object for storing camera parameters

`cameraParams = cameraParameters`

cameraParams = cameraParameters(Name,Value)

cameraParams = cameraParameters(paramStruct)

returns
an object that contains the intrinsic, extrinsic, and lens distortion
parameters of a camera.`cameraParams`

= cameraParameters

configures
the camera parameters object properties, specified as one or more `cameraParams`

= cameraParameters(`Name,Value`

)`Name,Value`

pair
arguments. Unspecified properties use default values.

returns
a `cameraParams`

= cameraParameters(`paramStruct`

)`cameraParameters`

object
containing the parameters specified by `paramStruct`

input. `paramStruct`

is
returned by the `toStruct`

method.

The object contains intrinsic, extrinsic, lens distortion, and estimation properties.

Specify optional comma-separated pairs of `Name,Value`

arguments.
`Name`

is the argument
name and `Value`

is the corresponding
value. `Name`

must appear
inside single quotes (`' '`

).
You can specify several name and value pair
arguments in any order as `Name1,Value1,...,NameN,ValueN`

.

`'RadialDistortion'`

,```
[0 0
0]
```

sets the `'RadialDistortion'`

to ```
[0
0 0]
```

.`'IntrinsicMatrix'`

— Projection matrix3-by-3 identity matrix (default) | 3-by-3 intrinsic matrix

Projection matrix, specified as the comma-separated pair consisting
of '`IntrinsicMatrix`

' and a 3-by-3 matrix. For
the matrix format, the object uses the following format:

$$\left[\begin{array}{ccc}{f}_{x}& 0& 0\\ s& {f}_{y}& 0\\ {c}_{x}& {c}_{y}& 1\end{array}\right]$$

The coordinates [*c _{x}*

`0`

. = f_{x}*Fs_{x} |

= f_{y}*Fs_{y} |

, is the focal length in world units,
typically expressed in millimeters.F |

[s_{x}, s_{y}]
are the number of pixels per world unit in the and x direction
respectively. y |

and f_{x} are
expressed in pixels.f_{y} |

`'RadialDistortion'`

— Radial distortion coefficients`[0 0 0] `

(default) | 2-element vector | 3-element vectorRadial distortion coefficients, specified as the comma-separated
pair consisting of '`RadialDistortion`

' and either
a 2- or 3-element vector. If you specify a 2-element vector, the object
sets the third element to `0`

.

Radial distortion occurs when light rays bend more near the edges of a lens than they do at its optical center. The smaller the lens, the greater the distortion.

The camera parameters object calculates the radial distorted
location of a point. You can denote the distorted points as (*x*_{distorted}, *y*_{distorted}),
as follows:

*x*_{distorted} = * x*(1
+

*y*_{distorted}= * y*(1
+

, x = undistorted pixel
locationsy |

k_{1}, k_{2},
and k_{3} = radial distortion
coefficients of the lens |

r^{2} = x^{2} + y^{2} |

Typically, two coefficients are sufficient. For severe
distortion, you can include *k*_{3}.
The undistorted pixel locations appear in normalized image coordinates,
with the origin at the optical center. The coordinates are expressed
in world units.

`'TangentialDistortion'`

— Tangential distortion coefficients`[0 0]'`

(default) | 2-element vectorTangential distortion coefficients, specified as the comma-separated
pair consisting of '`TangentialDistortion`

' and
a 2-element vector. Tangential distortion occurs when the lens and
the image plane are not parallel.

The camera parameters object calculates the tangential distorted
location of a point. You can denote the distorted points as (*x*_{distorted}, *y*_{distorted}),
as follows:

*x*_{distorted} = * x* +
[2 *

*y*_{distorted} = * y* +
[

, x = undistorted pixel
locationsy |

p_{1} and p_{2} =
tangential distortion coefficients of the lens |

r^{2} = x^{2} + y^{2} |

The undistorted pixel locations appear in normalized image coordinates, with the origin at the optical center. The coordinates are expressed in world units.

`'ImageSize'`

— Image size produced by camera1-by-2 [

Image size produced by camera, specified as the comma-separated
pair consisting of '`ImageSize`

' and as 1-by-2
[* mrows*,

`'RotationVectors'`

— Camera rotations`[]`

Camera rotations, specified as the comma-separated pair consisting
of '`RotationVectors`

' and an * M*-by-3
matrix. The matrix contains rotation vectors for

Each vector specifies the 3-D axis about which the camera is rotated. The magnitude of the vector represents the angle of rotation in radians. You can convert any rotation vector to a 3-by-3 rotation matrix using the Rodrigues formula.

You must set the `RotationVectors`

and `TranslationVectors`

properties
together in the constructor to ensure that the number of rotation
vectors equals the number of translation vectors. Setting only one
property but not the other results in an error.

`'TranslationVectors'`

— Camera translations`[]`

Camera translations, specified as the comma-separated pair consisting
of '`RotationVectors`

' and an * M*-by-3
matrix. This matrix contains translation vectors for

The following equation provides the transformation that relates
a world coordinate [*X**Y** Z*]
and the corresponding image point [

$$s\left[\begin{array}{ccc}x& y& 1\end{array}\right]=\left[\begin{array}{cccc}X& Y& Z& 1\end{array}\right]\left[\begin{array}{c}R\\ t\end{array}\right]K$$

is the 3-D rotation matrix.R |

is the translation vector.t |

is the K`IntrinsicMatrix` . |

is a scalar.s |

This equation does not take distortion into consideration.
Distortion is removed by the `undistortImage`

function.

You must set the `RotationVectors`

and `TranslationVectors`

properties
together in the constructor to ensure that the number of rotation
vectors equals the number of translation vectors. Setting only one
property results in an error.

`'WorldPoints'`

— World coordinates`[]`

World coordinates of key points on calibration pattern, specified
as the comma-separated pair consisting of '`WorldPoints`

'
and an * M*-by-2 array.

`'WorldUnits'`

— World points units`'mm'`

(default) | character vectorWorld points units, specified as the comma-separated pair consisting
of '`WorldUnits`

' and a character vector. The character
vector describes the units of measure.

`'EstimateSkew'`

— Estimate skew flag`false`

(default) | logical scalarEstimate skew flag, specified as the comma-separated pair consisting
of '`EstimateSkew`

' and a logical scalar. When
you set the logical to `true`

, the object estimates
the image axes skew. When you set the logical to `false`

,
the image axes are exactly perpendicular.

`'NumRadialDistortionCoefficients'`

— Number of radial distortion coefficients`2`

(default) | `3`

Number of radial distortion coefficients, specified as the comma-separated
pair consisting of '`NumRadialDistortionCoefficients`

'
and the number '`2`

' or '`3`

'.

`'EstimateTangentialDistortion'`

— Estimate tangential distortion flag`false`

(default) | logical scalarEstimate tangential distortion flag, specified as the comma-separated
pair consisting of '`EstimateTangentialDistortion`

'
and the logical scalar `true`

or `false`

.
When you set the logical to `true`

, the object estimates
the tangential distortion. When you set the logical to `false`

,
the tangential distortion is negligible.

`'ReprojectionErrors'`

— Reprojection errors`[]`

(default) | Reprojection errors, specified as the comma-separated pair of
'`ReprojectionErrors`

' and an * M*-by-2-by-

**Intrinsic camera parameters:**

`IntrinsicMatrix`

— Projection matrix3-by-3 identity matrix

Projection matrix, specified as a 3-by-3 identity matrix. The object uses the following format for the matrix format:

$$\left[\begin{array}{ccc}{f}_{x}& 0& 0\\ s& {f}_{y}& 0\\ {c}_{x}& {c}_{y}& 1\end{array}\right]$$

The coordinates [*c _{x}*

`0`

. = f_{x}*Fs_{x} |

= f_{y}*Fs_{y} |

, is the focal length in world units,
typically expressed in millimeters.F |

[s_{x}, s_{y}]
are the number of pixels per world unit in the and x direction
respectively. y |

and fx are expressed
in pixels.fy |

`PrincipalPoint`

— Optical center2-element vector

Optical center, specified as a 2-element vector [* cx*,

`FocalLength`

— Focal length2-element vector

Focal length in * x* and

= F * fxsx |

= F * fysy |

where, F is the focal length in world units, typically
in millimeters, and [* sx*,

`Skew`

— Camera axes skew`0`

(default) | scalarCamera axes skew, specified as a scalar. If the * x* and
the

`0`

.**Camera lens distortion:**

`RadialDistortion`

— Radial distortion coefficients`[0 0 0] `

(default) | 2-element vector | 3-element vectorRadial distortion coefficients, specified as either a 2- or
3-element vector. When you specify a 2-element vector, the object
sets the third element to `0`

. Radial distortion
occurs when light rays bend more near the edges of a lens than they
do at its optical center. The smaller the lens, the greater the distortion.
The camera parameters object calculates the radial distorted location
of a point. You can denote the distorted points as (*x*_{distorted}, *y*_{distorted}),
as follows:

*x*_{distorted} = * x*(1
+

*y*_{distorted}= * y*(1
+

, x = undistorted pixel
locationsy |

k_{1}, k_{2},
and k_{3} = radial distortion
coefficients of the lens |

r^{2} = x^{2} + y^{2} |

Typically, two coefficients are sufficient. For severe
distortion, you can include *k*_{3}.
The undistorted pixel locations appear in normalized image coordinates,
with the origin at the optical center. The coordinates are expressed
in world units.

`TangentialDistortion`

— Tangential distortion coefficients`[0 0]'`

(default) | 2-element vectorTangential distortion coefficients, specified as a 2-element
vector. Tangential distortion occurs when the lens and the image plane
are not parallel. The camera parameters object calculates the tangential
distorted location of a point. You can denote the distorted points
as (*x*_{distorted}, *y*_{distorted}),
as follows:

*x*_{distorted} = * x* +
[2 *

*y*_{distorted} = * y* +
[

, x = undistorted pixel
locationsy |

p_{1} and p_{2} =
tangential distortion coefficients of the lens |

r^{2} = x^{2} + y^{2} |

The undistorted pixel locations appear in normalized image coordinates, with the origin at the optical center. The coordinates are expressed in world units.

**Extrinsic camera parameters:**

`RotationMatrices`

— 3-D rotation matrix3-by-3-by-

3-D rotation matrix, specified as a 3-by-3-by-* P*,
with

The following equation provides the transformation that relates
a world coordinate in the checkerboard's frame [*X**Y** Z*]
and the corresponding image point [

$$s\left[\begin{array}{ccc}x& y& 1\end{array}\right]=\left[\begin{array}{cccc}X& Y& Z& 1\end{array}\right]\left[\begin{array}{c}R\\ t\end{array}\right]K$$

is the 3-D rotation matrix.R |

is the translation vector.t |

is the K`IntrinsicMatrix` . |

is a scalar.s |

This equation does not take distortion into consideration.
Distortion is removed by the `undistortImage`

function.

`RotationVectors`

— 3-D rotation vectors`[]`

(default) | 3-D rotation vectors , specified as a * M*-by-3
matrix containing

`RotationMatrices`

property`TranslationVectors`

— Camera translations`[]`

Camera translations, specified as an * M*-by-3
matrix. This matrix contains translation vectors for

The following equation provides the transformation that relates
a world coordinate in the checkerboard's frame [*X**Y** Z*]
and the corresponding image point [

$$s\left[\begin{array}{ccc}x& y& 1\end{array}\right]=\left[\begin{array}{cccc}X& Y& Z& 1\end{array}\right]\left[\begin{array}{c}R\\ t\end{array}\right]K$$

is the 3-D rotation matrix.R |

is the translation vector.t |

is the K`IntrinsicMatrix` . |

is a scalar.s |

This equation does not take distortion into consideration.
Distortion is removed by the `undistortImage`

function.

You must set the `RotationVectors`

and `TranslationVectors`

properties
in the constructor to ensure that the number of rotation vectors equals
the number of translation vectors. Setting only one property but not
the other results in an error.

**Estimated camera parameter
accuracy:**

`MeanReprojectionError`

— Average Euclidean distancenumeric value (read-only)

Average Euclidean distance between reprojected and detected points, specified as a numeric value in pixels.

`ReprojectionErrors`

— Estimated camera parameters accuracyEstimated camera parameters accuracy, specified as an * M*-by-2-by-

`ReprojectedPoints`

— World points reprojected onto calibration imagesWorld points reprojected onto calibration images, specified
as an * M*-by-2-by-

**Estimate camera parameters
settings:**

`NumPatterns`

— Number of calibrated patternsinteger

Number of calibration patterns that estimates camera extrinsics, specified as an integer. The number of calibration patterns equals the number of translation and rotation vectors.

`WorldPoints`

— World coordinates`[]`

World coordinates of key points on calibration pattern, specified
as an * M*-by-2 array.

`WorldUnits`

— World points units`'mm'`

(default) | character vectorWorld points units, specified as a character vector. The character vector describes the units of measure.

`EstimateSkew`

— Estimate skew flag`false`

(default) | logical scalarEstimate skew flag, specified as a logical scalar. When you
set the logical to `true`

, the object estimates the
image axes skew. When you set the logical to `false`

,
the image axes are exactly perpendicular.

`NumRadialDistortionCoefficients`

— Number of radial distortion coefficients`2`

(default) | `3`

Number of radial distortion coefficients, specified as the number
'`2`

' or '`3`

'.

`EstimateTangentialDistortion`

— Estimate tangential distortion flag`false`

(default) | logical scalarEstimate tangential distortion flag, specified as the logical
scalar `true`

or `false`

. When you
set the logical to `true`

, the object estimates the
tangential distortion. When you set the logical to `false`

,
the tangential distortion is negligible.

pointsToWorld | Determine world coordinates of image points |

toStruct | Convert a camera parameters object into a struct |

worldToImage | Project world points into the image |

`cameraParams`

— Camera parameters`cameraParameters`

objectCamera parameters, returned as a `cameraParameters`

object. The object contains the intrinsic,
extrinsic, and lens distortion parameters of a camera.

This example shows you how to use the cameraParameters object in a workflow to remove distortion from an image. The example creates a cameraParameters object manually. In practice, use the estimateCameraParameters or the cameraCalibrator app to derive the object.

Create a cameraParameters object manually.

IntrinsicMatrix = [715.2699 0 0; 0 711.5281 0; 565.6995 355.3466 1]; radialDistortion = [-0.3361 0.0921]; cameraParams = cameraParameters('IntrinsicMatrix',IntrinsicMatrix,... 'RadialDistortion',radialDistortion);

Remove distortion from the image.

I = imread(fullfile(matlabroot,'toolbox','vision','visiondata',... 'calibration','fishEye','image01.jpg')); J = undistortImage(I,cameraParams);

Display the original and undistorted images.

figure; imshowpair(imresize(I,0.5), imresize(J,0.5), 'montage'); title('Original Image (left) vs. Corrected Image (right)');

[1] Zhang, Z. "A flexible new technique
for camera calibration". *IEEE Transactions on Pattern
Analysis and Machine Intelligence*, Vol. 22, No. 11, pp.
1330–1334, 2000.

[2] Heikkila, J, and O. Silven. "A
Four-step Camera Calibration Procedure with Implicit Image Correction", *IEEE
International Conference on Computer Vision and Pattern Recognition*,
1997.

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Use in a MATLAB Function block is not supported.

Use the

`toStruct`

method to pass a`cameraParameters`

object into generated code. See the Code Generation for Depth Estimation From Stereo Video example.

Camera Calibrator | `detectCheckerboardPoints`

| `estimateCameraParameters`

| `generateCheckerboardPoints`

| `showExtrinsics`

| `showReprojectionErrors`

| `stereoParameters`

| `undistortImage`

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Was this topic helpful?

You can also select a location from the following list:

- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)