Main Content

Calibrate a Monocular Camera

A monocular camera is a common type of vision sensor used in automated driving applications. When mounted on an ego vehicle, this camera can detect objects, detect lane boundaries, and track objects through a scene.

Before you can use the camera, you must calibrate it. Camera calibration is the process of estimating the intrinsic and extrinsic parameters of a camera using images of a calibration pattern, such as a checkerboard. After you estimate the intrinsic and extrinsic parameters, you can use them to configure a model of a monocular camera.

Estimate Intrinsic Parameters

The intrinsic parameters of a camera are the properties of the camera, such as its focal length and optical center. To estimate these parameters for a monocular camera, use Computer Vision Toolbox™ functions and images of a checkerboard pattern.

Alternatively, to better visualize the results, use the Camera Calibrator app. For information on setting up the camera, preparing the checkerboard pattern, and calibration techniques, see Using the Single Camera Calibrator App.

Place Checkerboard for Extrinsic Parameter Estimation

For a monocular camera mounted on a vehicle, the extrinsic parameters define the mounting position of that camera. These parameters include the rotation angles of the camera with respect to the vehicle coordinate system, and the height of the camera above the ground.

Before you can estimate the extrinsic parameters, you must capture an image of a checkerboard pattern from the camera. Use the same checkerboard pattern that you used to estimate the intrinsic parameters.

The checkerboard uses a pattern-centric coordinate system (XP, YP), where the XP-axis points to the right and the YP-axis points down. The checkerboard origin is the bottom-right corner of the top-left square of the checkerboard.

Checkerboard with axes and origin labeled

When placing the checkerboard pattern in relation to the vehicle, the XP- and YP-axes must align with the XV- and YV-axes of the vehicle. In the vehicle coordinate system, the XV-axis points forward from the vehicle and the YV-axis points to the left, as viewed when facing forward. The origin is on the road surface, directly below the camera center (the focal point of the camera).

Top-down view of vehicle with axes and origin labeled

The orientation of the pattern can be either horizontal or vertical.

Horizontal Orientation

In the horizontal orientation, the checkerboard pattern is either on the ground or parallel to the ground. You can place the pattern in front of the vehicle, in back of the vehicle, or on the left or right side of the vehicle.

Vehicle with horizontal checkerboard pattern placements from front, back, left, and right sides

Vertical Orientation

In the vertical orientation, the checkerboard pattern is perpendicular to the ground. You can place the pattern in front of the vehicle, in back of the vehicle, or on the left of right side of the vehicle.

Vehicle with vertical checkerboard pattern placements from front, back, left, and right sides

Estimate Extrinsic Parameters

After placing the checkerboard in the location you want, capture an image of it using the monocular camera. Then, use the estimateMonoCameraParameters function to estimate the extrinsic parameters. To use this function, you must specify the following:

  • The intrinsic parameters of the camera

  • The key points detected in the image, in this case the corners of the checkerboard squares

  • The world points of the checkerboard

  • The height of the checkerboard pattern's origin above the ground

For example, for image I and intrinsic parameters intrinsics, the following code estimates the extrinsic parameters. By default, estimateMonoCameraParameters assumes that the camera is facing forward and that the checkerboard pattern has a horizontal orientation.

[imagePoints,boardSize] = detectCheckerboardPoints(I);
squareSize = 0.029; % Square size in meters
worldPoints = generateCheckerboardPoints(boardSize,squareSize);
patternOriginHeight = 0; % Pattern is on ground
[pitch,yaw,roll,height] = estimateMonoCameraParameters(intrinsics, ...
                             imagePoints,worldPoints,patternOriginHeight);

To increase estimation accuracy of these parameters, capture multiple images and average the values of the image points.

Configure Camera Using Intrinsic and Extrinsic Parameters

Once you have the estimated intrinsic and extrinsic parameters, you can use the monoCamera object to configure a model of the camera. The following sample code shows how to configure the camera using parameters intrinsics, height, pitch, yaw, and roll:

monoCam = monoCamera(intrinsics,height,'Pitch',pitch,'Yaw',yaw,'Roll',roll);

See Also

Apps

Functions

Objects

Related Examples

More About