Main Content

estimateMultiCameraParameters

Calibrate extrinsic parameters of multiple cameras with overlapping views

Since R2025a

Description

[cameraParams,imagesUsed] = estimateMultiCameraParameters(imagePoints,worldPoints,intrinsics) returns an object cameraParams, estimates extrinsic parameters of multiple cameras using images of a single calibration pattern. The extrinsic parameters include the rotation and translation that describe the position and orientation of each camera with respect to the reference camera. The function also returns the images you used to estimate the camera parameters. The function adjusts all image points for distortion according to the lens distortion parameters specified in the intrinsics input.

example

cameraParams = estimateMultiCameraParameters(___,Name=Value) specifies options using one or more name-value arguments in addition to any combination of arguments from previous syntaxes. For example, WorldUnits="mm" sets the world units to millimeters.

Examples

collapse all

Estimate the relative position and orientation of six cameras with overlapping fields of view by using calibration images that contain a single ChArUco board.

Download the calibration images.

calibImagesURL = "https://www.mathworks.com/supportfiles/vision/data/overlapping-cameras-charuco.zip";
calibImagesDir = fullfile(pwd,"overlapping-cameras-charuco");
calibImagesZip = fullfile(pwd,"overlapping-cameras-charuco.zip");
if ~exist(calibImagesZip,"file")
    disp("Downloading calibration images (52 MB)...")
    websave(calibImagesZip,calibImagesURL);
end
if ~exist(calibImagesDir,"dir")
    unzip(calibImagesZip,pwd)
end

Specify calibration image filenames for each camera.

numCameras = 6;
camDirPrefix = "Cam00";
imageFiles = cell(1,numCameras);
for i = 1:numCameras
    camDir = fullfile(calibImagesDir,camDirPrefix+i);
    imds = imageDatastore(camDir);
    imageFiles{i} = imds.Files;
end
imageFiles = [imageFiles{:}];

Define the ChArUco board properties. Specify checker size and marker size in centimeters.

markerFamily = "DICT_6X6_1000";
patternDims = [5 5];
markerSize = 6.8;   % in cm
checkerSize = 9.15; % in cm
numKeyPoints = prod(patternDims - 1);

Create a function handle for detectCharucoBoardPoints that specifies the non-zero minimum marker ID of the board.

minMarkerId = 144;
funcHandle = @(image) detectCharucoBoardPoints(image,patternDims, ...
    markerFamily,checkerSize,markerSize,MinMarkerID=minMarkerId);

Detect the key points of the ChArUco board in the calibration images.

imagePoints = detectPatternPoints(imageFiles,funcHandle,numKeyPoints);
[==================================================] 100%
Elapsed time: 00:00:04
Estimated time remaining: 00:00:00

Generate the world points for the pattern.

worldPoints = patternWorldPoints("charuco-board",patternDims,checkerSize);

Load the intrinsic parameters of the six cameras. These parameters have been estimated using the Using the Single Camera Calibrator App.

ld = load("sixCameraIntrinsics.mat");

Perform multi-camera calibration.

params = estimateMultiCameraParameters(imagePoints,worldPoints,ld.intrinsics,WorldUnits="cm");

Visualize the calibration accuracy.

figure(Position=[100,100,1000,400])
showReprojectionErrors(params)

Figure contains 3 axes objects. Axes object 1 with title Mean Reprojection Error per Image, xlabel View, ylabel Camera contains an object of type patch. Axes object 2 with title Mean Reprojection Error per View, xlabel View, ylabel Mean Error in Pixels contains 2 objects of type bar, line. This object represents Overall Mean Error: 0.37 pixels. Axes object 3 with title Mean Reprojection Error per Camera, xlabel Camera, ylabel Mean Error in Pixels contains 2 objects of type bar, line.

Visualize the camera extrinsic parameters.

figure
showExtrinsics(params)
view(2)

Figure contains an axes object. The axes object with title Extrinsic Parameters Visualization, xlabel X (cm), ylabel Z (cm) contains 56 objects of type patch, text, line.

Input Arguments

collapse all

Image coordinates of key points in calibration pattern, specified as a numKeyPoints-by-2-by-numViews-by-numCameras array of x-y image coordinates. numKeyPoints is the number of key points in each view, numViews is the number of views with respect to the camera, and numCameras is the number of cameras. For example, imagePoints(:,:,i,j) contains the points from camera j when the pattern is located at the ith view. At each view, the pattern must be visible to at least two cameras. Each camera should observe the pattern at least once along with some other cameras.

To include partially detected patterns, use [NaN,NaN] as x-y coordinates for missing keypoints. Use the detectPatternPoints function to detect calibration pattern keypoints in images from multiple cameras.

Data Types: double

World coordinates of keypoints on calibration pattern, specified as an numKeyPoints-by-2 array. numKeyPoints is the number of keypoints. Each keypoint is of the form [x,y]. The pattern must be planar, so all z-coordinates are assumed to be 0.

Data Types: double

Intrinsic parameters of each camera, specified as an numCameras-element array. numCameras is the number of cameras and each element is either a cameraIntrinsics or fisheyeIntrinsics object.

  • If all cameras share the same model (lens characteristics), the array is contains cameraIntrinsics or fisheyeIntrinsics objects.

  • If different models are used across the cameras, the array is a cell array, with each cell containing a different type of camera intrinsics object.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: estimateMultiCameraParameters(imagePoints,worldPoints,intrinsics,WorldUnits="mm") sets the world units to millimeters.

Units of world points, specified as a character vector or string scalar.

Index of the camera that defines the reference coordinate system, specified as an integer. All other camera poses are defined relative to the reference camera. The pose of the reference camera is represented by a rigidtform3d object initialized with the identity matrix, eye(4).

Output Arguments

collapse all

Parameters of a multi-camera system, returned as a multiCameraParameters object.

Images you use to estimate camera parameters, returned as a numViews-by-numCameras logical array. numViews corresponds to the number of camera views used and numCameras is the number of cameras. The array indicates which images you used to estimate the camera parameters. A logical true value in the array indicates which images you used to estimate the camera parameters.

Version History

Introduced in R2025a