天天看點

matlab stereo view,Stereo Camera Calibrator App

Stereo Camera Calibrator AppStereo Camera Calibrator Overview

You can use the

The

Rectify stereo images using the rectifyStereoImages function.

Reconstruct the 3-D scene using the reconstructScene function.

Compute 3-D locations corresponding to matching pairs of image points using the triangulate function.

The suite of calibration functions used by the ® workspace. For a list of calibration functions, see Camera Calibration.

Note

You can use the Camera Calibrator app with cameras up to a field of view (FOV) of 95

degrees.Stereo Camera Calibration

matlab stereo view,Stereo Camera Calibrator App

Follow this workflow to calibrate your stereo camera using the app:

Prepare images, camera, and calibration pattern.

Add image pairs.

Calibrate the stereo camera.

Evaluate calibration accuracy.

Adjust parameters to improve accuracy (if necessary).

Export the parameters object.

In some cases, the default values work well, and you do not need to make any improvements

before exporting parameters. You can also make improvements using the camera calibration

functions directly in the MATLAB workspace. For a list of functions, see Camera Calibration.Open the Stereo Camera Calibrator

MATLAB Toolstrip: On the Apps tab, in the Image

Processing and Computer Vision section, click the Stereo Camera

Calibrator icon.

MATLAB command prompt: Enter stereoCameraCalibratorPrepare Pattern, Camera, and Images

To improve the results, use between 10 and 20 images of the calibration pattern. The

calibrator requires at least three images. Use uncompressed images or lossless compression

formats such as PNG. The calibration pattern and the camera setup must satisfy a set of

requirements to work with the calibrator. For greater calibration accuracy, follow these

instructions for preparing the pattern, setting up the camera, and capturing the images.

The Camera Calibration for the list of

functions.

You can print (from MATLAB) and use the checkerboard

pattern provided. The checkerboard pattern you use must not be square. One side must

contain an even number of squares and the other side must contain an odd number of squares.

Therefore, the pattern contains two black corners along one side and two white corners on the

opposite side. This criteria enables the app to determine the orientation of the pattern. The

calibrator assigns the longer side to be the x-direction.

matlab stereo view,Stereo Camera Calibrator App

To prepare the checkerboard pattern:

Attach the checkerboard printout to a flat surface. Imperfections on the surface can

affect the accuracy of the calibration.

Measure one side of the checkerboard square. You need this measurement for calibration.

The size of the squares can vary depending on printer settings.

matlab stereo view,Stereo Camera Calibrator App

To improve the detection speed, set up the pattern with as little background clutter as

possible.

To calibrate your camera, follow these rules:

Keep the pattern in focus, but do not use autofocus.

If you change zoom settings between images, the focal length changes.

For best results, use at least 10 to 20 images of the calibration pattern. The calibrator

requires at least three images. Use uncompressed images or images in lossless compression

formats such as PNG. For greater calibration accuracy:

Capture the images of the pattern at a distance roughly equal to the distance from your

camera to the objects of interest. For example, if you plan to measure objects from 2 meters,

keep your pattern approximately 2 meters from the camera.

Place the checkerboard at an angle less than 45 degrees relative to the camera plane.

matlab stereo view,Stereo Camera Calibrator App

Do not modify the images, (for example, do not crop them).

Do not use autofocus or change the zoom settings between images.

Capture the images of a checkerboard pattern at different orientations relative to the camera.

Capture a variety of images of the pattern so that you have accounted for as much of the

image frame as possible. Lens distortion increases radially from the center of the image and

sometimes is not uniform across the image frame. To capture this lens distortion, the pattern

must appear close to the edges of the captured images.

matlab stereo view,Stereo Camera Calibrator App

Make sure the checkerboard pattern is fully visible in both images of each stereo pair.

matlab stereo view,Stereo Camera Calibrator App

Keep the pattern stationary for each image pair. Any motion of the pattern between

taking image 1 and image 2 of the pair negatively affects the calibration.

Create a stereo display, or anaglyph, by positioning the two cameras approximately 55 mm

apart. This distance represents the average distance between human eyes.

For greater reconstruction accuracy at longer distances, position your cameras farther

apart.Add Image Pairs

To begin calibration, click Add images, to select two sets of stereo

images of the checkerboard, one set from each camera.

You can add images from multiple folders by clicking Add images in the

File section of the Calibration tab. Select the

location for the images corresponding to camera 1 using the Browse

button, then do the same for camera 2. Specify Size of checkerboard square

by entering the length of one side of a square from the checkerboard pattern.

matlab stereo view,Stereo Camera Calibrator App

The calibrator attempts to detect a checkerboard in each of the added images, displaying an

Analyzing Images progress bar window, indicating detection progress. If any of the images are

rejected, the Detection Results dialog box appears, which contains diagnostic information. The

results indicate how many total images were processed, and of those processed, how many were

accepted, rejected, or skipped. The calibrator skips duplicate images.

matlab stereo view,Stereo Camera Calibrator App

To view the rejected images, click View images. The calibrator

rejects duplicate images. It also rejects images where the entire checkerboard could not be

detected. Possible reasons for no detection are a blurry image or an extreme angle of the

pattern. Detection takes longer with larger images and with patterns that contain a large number

of squares.

The Data Browser pane displays a list of image pairs with IDs. These

image pairs contain a detected pattern. To view an image, select it from the Data

Browser pane.

matlab stereo view,Stereo Camera Calibrator App

The Image pane displays the selected checkerboard image

pair with green circles to indicate detected points. You can verify that the corners were

detected correctly using the zoom controls. The yellow square indicates the (0,0) origin. The X

and Y arrows indicate the checkerboard axes orientation.

You can choose for the app to compute camera intrinsics or you can load pre-computed fixed

intrinsics. To load intrinsics into the app, select Use Fixed Intrinsics in

the Intrinsics section of the Calibration tab. The Radial

Distortion and Compute options in the

Options section are disabled when you load intrinsics.

To load intrinsics as variables from your workspace, click Load

Intrinsics. For example, if the wideBaselineStereo struct

contains the intrinsics for both

cameras.

ld = load('wideBaselineStereo');

int1 = ld.intrinsics1

int2 = ld.intrinsics2Then,

click Load Intrinsics to specify these variables in the dialog box, as shown.

matlab stereo view,Stereo Camera Calibrator App

Calibrate

Once you are satisfied with the accepted image pairs, click the

Calibrate button on the Calibration tab. The default

calibration settings assume the minimum set of camera parameters. Start by running the

calibration with the default settings. After evaluating the results, you can try to improve

calibration accuracy by adjusting the settings and adding or removing images, and then calibrate

again.

When the camera has severe lens distortion, the app can fail to compute the initial values for

the camera intrinsics. If you have the manufacturer’s specifications for your camera and know

the pixel size, focal length, or lens characteristics, you can manually set initial guesses for

camera intrinsics and radial distortion. To set initial guesses, click

Options > Optimization Options.

Note

These options are not available for preloaded intrinsics.

Select the top checkbox and then enter a 3-by-3 matrix to specify initial intrinsics. If

you do not specify an initial guess, the function computes the initial intrinsic matrix using

linear least squares.

Select the bottom checkbox and then enter a 2- or 3-element vector to specify the

initial radial distortion. If you do not provide a value, the function uses

0 as the initial value for all the coefficients.Evaluate Calibration Results

You can evaluate calibration accuracy by examining the reprojection errors, examining the

camera extrinsics, or viewing the undistorted image. For best calibration results, use all three

methods of evaluation.

matlab stereo view,Stereo Camera Calibrator App

The reprojection errors are the distances, in pixels, between the

detected and the reprojected points. The

matlab stereo view,Stereo Camera Calibrator App

The Data

Browser pane.

Reprojection Errors Bar Graph

The bar graph

displays the mean reprojection error per image, along with the overall mean error. The bar

labels correspond to the image IDs. The highlighted bars correspond to the selected image pair.

matlab stereo view,Stereo Camera Calibrator App

Select an image pair in one of these ways:

Clicking the corresponding bar in the graph.

Select the image pair from the list in the Data

Browser pane.

Adjust the overall mean error. Click and slide the red line up or down to select outlier

images.

The 3-D extrinsic parameters plot provides a camera-centric view of the patterns and a

pattern-centric view of the camera. The camera-centric view is helpful if the camera was

stationary when the images were captured. The pattern-centric view is helpful if the pattern was

stationary. You can click the cursor and hold down the mouse button with the rotate icon to

rotate the figure. Click a checkerboard (or camera) to select it. The highlighted data in the

visualizations correspond to the selected image in the list. Examine the relative positions of

the pattern and the camera to determine if they match what you expect. For example, a pattern

that appears behind the camera indicates a calibration error.

matlab stereo view,Stereo Camera Calibrator App

To view the effects of stereo rectification, click Show Rectified in the

View section of the Calibration tab. If the

calibration was accurate, the images become undistorted and row-aligned.

matlab stereo view,Stereo Camera Calibrator App

Checking the rectified images is important even if the reprojection errors are

low. For example, if the pattern covers only a small percentage of the image, the distortion

estimation might be incorrect, even though the calibration resulted in few reprojection

errors.The following image shows an example of this type of incorrect estimation for a single

camera calibration.

matlab stereo view,Stereo Camera Calibrator App

Improve Calibration

To improve the calibration, you can remove high-error image

pairs, add more image pairs, or modify the calibrator settings.

Consider adding more images if:

You have less than 10 images.

The patterns do not cover enough of the image frame.

The patterns do not have enough variation in orientation with respect to the

camera.

Consider removing images if the images:

The images have a high mean reprojection error.

The images are blurry.

The images contain a checkerboard at an angle greater than 45 degrees relative to the

camera plane.

matlab stereo view,Stereo Camera Calibrator App

The images contain incorrectly detected checkerboard points.

You can specify 2 or 3 radial distortion coefficients by selecting

the corresponding radio button from the Options section. 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.

matlab stereo view,Stereo Camera Calibrator App

The radial distortion

coefficients model this type of distortion. The distorted points are

denoted as (xdistorted, ydistorted):

xdistorted = x(1

+ k1*r2 + k2*r4 + k3*r6)

ydistorted= y(1

+ k1*r2 + k2*r4 + k3*r6)

x, y —

Undistorted pixel locations. x and y are

in normalized image coordinates. Normalized image coordinates are

calculated from pixel coordinates by translating to the optical center

and dividing by the focal length in pixels. Thus, x and y are

dimensionless.

k1, k2,

and k3 — Radial distortion

coefficients of the lens.

r2: x2 + y2

Typically, two coefficients are sufficient for calibration.

For severe distortion, such as in wide-angle lenses, you can select

3 coefficients to include k3.

When you select the Compute Skew

check box, the calibrator estimates the image axes skew. Some camera sensors contain

imperfections that cause the x- and y-axes of the image to

not be perpendicular. You can model this defect using a skew parameter. If you do not select the

check box, the image axes are assumed to be perpendicular, which is the case for most modern

cameras.

Tangential distortion occurs when the lens and the image plane

are not parallel. The tangential distortion coefficients model this

type of distortion.

matlab stereo view,Stereo Camera Calibrator App

The distorted

points are denoted as (xdistorted, ydistorted):

xdistorted = x +

[2 * p1 * x * y + p2 *

(r2 + 2 * x2)]

ydistorted = y +

[p1 * (r2 +

2 *y2) + 2 * p2 * x * y]

x, y —

Undistorted pixel locations. x and y are

in normalized image coordinates. Normalized image coordinates are

calculated from pixel coordinates by translating to the optical center

and dividing by the focal length in pixels. Thus, x and y are

dimensionless.

p1 and p2 —

Tangential distortion coefficients of the lens.

r2:

x2 +

y2

When you select the Compute Tangential Distortion check box, the

calibrator estimates the tangential distortion coefficients. Otherwise, the calibrator sets the

tangential distortion coefficients to zero.Export Camera Parameters

When you are satisfied with calibration accuracy, click Export Camera

Parameters. You can either save and export the camera parameters to an object by

selecting Export Camera Parameters or generate the camera parameters as a

MATLAB script.

Select Export Camera Parameters > Export Parameters to Workspace to create a stereoParameters object in your workspace. The

object contains the intrinsic and extrinsic parameters of the camera and the distortion

coefficients. You can use this object for various computer vision tasks, such as image

undistortion, measuring planar objects, and 3-D reconstruction. See Measuring Planar Objects with a Calibrated Camera. You can

optionally export the stereoCalibrationErrors object, which contains the

standard errors of estimated stereo camera parameters, by selecting the Export

estimation errors check box.

Select Export Camera Parameters > Generate MATLAB script to save your camera parameters to a MATLAB script, enabling you to reproduce the steps from your calibration session.

References

[1] Zhang, Z. “A Flexible New Technique

for Camera Calibration”. IEEE Transactions on Pattern

Analysis and Machine Intelligence.Vol. 22, No. 11, 2000,

pp. 1330–1334.

[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.

See Also

Related Examples

More About

External Websites