Main Content

showReprojectionErrors

Visualize calibration errors

Description

showReprojectionErrors(cameraParams) displays a bar graph that represents the calibration accuracy for a single camera or for a stereo pair. The bar graph displays the mean reprojection error per image. The cameraParams input contains either a cameraParameters, fisheyeParameters, or a stereoParameters object, which the estimateCameraParameters or estimateFisheyeParameters function returns.

example

showReprojectionErrors(cameraParams,view) displays the reprojection errors using the visualization style specified by the view input.

example

showReprojectionErrors(___,Name,Value) uses additional options specified by one or more Name,Value pair arguments, using any of the preceding syntaxes.

example

ax = showReprojectionErrors(___) returns the plot axis, using any of the preceding syntaxes.

example

Examples

collapse all

Create a set of calibration images.

images = imageDatastore(fullfile(toolboxdir('vision'),'visiondata', ...
  'calibration','webcam'));
imageFileNames = images.Files(1:5);

Detect calibration pattern.

[imagePoints, boardSize] = detectCheckerboardPoints(imageFileNames);

Generate world coordinates of the corners of the squares. The square size is in millimeters.

squareSize = 25;
worldPoints = patternWorldPoints('checkerboard',boardSize,squareSize);

Calibrate the camera.

I = readimage(images,1); 
imageSize = [size(I, 1), size(I, 2)];
params = estimateCameraParameters(imagePoints,worldPoints, ...
                                  'ImageSize',imageSize);

Visualize the errors as a bar graph.

subplot(1,2,1);
showReprojectionErrors(params);

Figure contains an axes object. The axes object with title Mean Reprojection Error per Image, xlabel Images, ylabel Mean Error in Pixels contains 3 objects of type bar, line. This object represents Overall Mean Error: 0.25 pixels.

Visualize the errors as a scatter plot.

subplot(1,2,2);
showReprojectionErrors(params,'ScatterPlot');

Figure contains 2 axes objects. Axes object 1 with title Mean Reprojection Error per Image, xlabel Images, ylabel Mean Error in Pixels contains 3 objects of type bar, line. This object represents Overall Mean Error: 0.25 pixels. Axes object 2 with title Reprojection Errors in Pixels, xlabel X, ylabel Y contains 5 objects of type line. One or more of the lines displays its values using only markers These objects represent 1, 2, 3, 4, 5.

Specify calibration images

imageDir = fullfile(toolboxdir('vision'),'visiondata', ...
    'calibration','stereo');
leftImages = imageDatastore(fullfile(imageDir,'left'));
rightImages = imageDatastore(fullfile(imageDir,'right'));

Detect the checkerboards.

[imagePoints, boardSize] = detectCheckerboardPoints(...
     leftImages.Files,rightImages.Files);

Specify world coordinates of checkerboard keypoints. The square size is in millimeters.

squareSize = 108; 
worldPoints = patternWorldPoints('checkerboard',boardSize,squareSize);

Calibrate the stereo camera system. Here both cameras have the same resolution.

I = readimage(leftImages,1); 
imageSize = [size(I, 1), size(I, 2)];
params = estimateCameraParameters(imagePoints,worldPoints, ...
                                  'ImageSize',imageSize);

Visualize calibration accuracy.

showReprojectionErrors(params);

Figure contains an axes object. The axes object with title Mean Reprojection Error per Image, xlabel Image Pairs, ylabel Mean Error in Pixels contains 5 objects of type bar, line. These objects represent Camera 1, Camera 2, Overall Mean Error: 0.06 pixels.

Input Arguments

collapse all

Object containing parameters of single camera or stereo pair, specified as either a cameraParameters, fisheyeParameters, or stereoParameters object. You can create the single camera or stereo pair input object using the estimateCameraParameters function. The fisheye parameters input object is created using estimateFisheyeParameters.

You can also use the Camera Calibrator app to create the cameraParameters input object, or use Stereo Camera Calibrator app to create the stereoParameters input object. See Using the Single Camera Calibrator App and Using the Stereo Camera Calibrator App.

Bar graph or scatter plot view, specified as either 'BarGraph' or 'ScatterPlot'. The view input sets the visualization for the camera extrinsic parameters. Set view to 'BarGraph' to display the mean error per image as a bar graph. Set view to 'ScatterPlot' to display the error for each point as a scatter plot. The 'ScatterPlot' option applies only to the single camera case.

Name-Value Arguments

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'view','BarGraph' displays the mean error per image as a bar graph.

Highlight selection index, specified as a scalar or a vector of integers. When you set the view to 'BarGraph', the function highlights the bars corresponding to the selected images. When you set the view to 'ScatterPlot', the function highlights the points corresponding to the selected images with circle markers.

Output axes, specified as the comma-separated pair consisting of 'Parent' and a scalar value. Specify output axes to display the visualization. You can obtain the current axes handle by returning the function to an output variable:

ax = showReprojectionErrors(cameraParams)

You can also use the gca function to get the current axes handle.

Example: showReprojectionErrors(cameraParams,'Parent',ax)

Output Arguments

collapse all

Current axes handle, returned as a scalar value. The function returns the handle to the current axes for the current figure.

Example: ax = showReprojectionErrors(cameraParams)

Version History

Introduced in R2014a