Using the Stereo Camera Calibrator App

您所在的位置:网站首页 calibrator Using the Stereo Camera Calibrator App

Using the Stereo Camera Calibrator App

2023-07-26 19:54| 来源: 网络整理| 查看: 265

Using the Stereo Camera Calibrator AppOpen the App

MATLAB Toolstrip: On the Apps tab, in the Image Processing and Computer Vision section, click the Stereo Camera Calibrator icon.

MATLAB command prompt: Enter stereoCameraCalibrator

Add Image Pairs and Select Camera Model

To begin calibration, you must add images. You can add saved images from a folder or add images directly from a camera. The calibrator analyzes the images to ensure they meet the calibrator requirements. The calibrator then detects the points on the pattern. For details on camera setup and capturing images, see Prepare Camera and Capture Images

 Add Images from File

On the Calibration tab, in the File section, click Add Images, and then select From file. You can add images from multiple folders by clicking Add images for each folder. Enter the location for the images corresponding to camera 1, or select it using the Browse button, and then do the same for camera 2. Specify the calibration pattern by selecting one from the Choose Pattern list, or, in the Custom Pattern section, select Import Pattern Detector. In the Properties section, specify the properties for your detector, and then select OK to add your images.

After you load images, the Image and Pattern Properties dialog appears. Before the calibrator can analyze the calibration patterns, you must select the calibration pattern to detect and set image properties for the pattern structure. For more details on this dialog, see Select Calibration Pattern and Set Properties.

 Analyze Images

The calibrator attempts to detect a pattern in each of the added stereo pairs, displaying a 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.

To view the rejected images, click View images. The calibrator rejects duplicate images. It also rejects images where the entire pattern 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.

 View Images and Detected Points

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.

The Image pane displays the selected 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 pattern axes orientation.

 Intrinsics

You can choose for the app to compute camera intrinsics, or you can load precomputed, fixed intrinsics. To load intrinsics into the app, on the Calibration tab, in the Intrinsics section, select Use Fixed Intrinsics. The Radial Distortion and Compute options in the Options section are disabled when you load intrinsics.

To load intrinsics as variables from your workspace, select Load Intrinsics. For example, if the wideBaselineStereo structure contains the intrinsics for both cameras, enter this code at the MATLAB command prompt.

ld = load("wideBaselineStereo"); int1 = ld.intrinsics1 int2 = ld.intrinsics2 Then, select Load Intrinsics to specify these variables in the Load intrinsics from Workspace dialog box.

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.

 Optimization

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 specifications for your camera and know the pixel size, focal length, or lens characteristics, you can manually set initial guesses for the camera intrinsics and radial distortion. To set initial guesses, select Options > Optimization Options.

Select Specify initial intrinsics as a 3-by-3 matrix of the form [fx 0 0; s fy 0; cx cy 1], 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 Specify initial radial distortion as 2- or 3-element vector, 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.

For more details on calibration parameters, see What Is Camera Calibration?.

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.

 Examine Reprojection Errors

The reprojection errors are the distances, in pixels, between the detected and the reprojected points. The Stereo Camera Calibrator app calculates reprojection errors by projecting points from world coordinates, defined by the pattern, into image coordinates. The app then compares the reprojected points to the corresponding detected points. As a general rule, mean reprojection errors of less than one pixel are acceptable.

The Stereo Calibration App displays, in pixels, the reprojection errors as a bar graph. The graph helps you to identify which images that adversely contribute to the calibration. Select the bar graph entry and remove the image from the list of images in 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 pair IDs. The highlighted bars correspond to the selected image pair.

Select an image pair in one of these ways:

Click a corresponding bar in the graph.

Select an 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 pairs containing an image with a mean error greater than the specified value.

 Examine Extrinsic Parameter Visualization

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 pattern (or the camera) in the display to select it. The highlighted data in the visualizations correspond to the selected image pair 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.

 Show Rectified Images

To view the effects of stereo rectification, on the Calibration tab, in the View section, select Show Rectified. If the calibration is accurate, the images become undistorted and row-aligned.

Note

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.

Improve Calibration

To improve the calibration, you can remove high-error images, add more images, or modify the calibrator settings.

Consider adding more image pairs if:

You have fewer than 10 image pairs.

The calibration patterns do not cover enough of the image frame.

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

Consider removing image pairs if the images:

Have a high mean reprojection error.

Are blurry.

Contain a calibration pattern at an angle greater than 45 degrees relative to the camera plane.

Incorrectly detected calibration pattern points.

 Change the Number of Radial Distortion Coefficients

You can specify two or three radial distortion coefficients by selecting the corresponding option 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.

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 three coefficients to include k3.

 Compute Skew

To estimate the skew of the image axes, on the Calibration tab, in the Camera Model section, select Options > Compute > 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 this option, the image axes are perpendicular, which is true for most modern cameras.

 Compute Tangential Distortion

Tangential distortion occurs when the lens and the image plane are not parallel. The tangential distortion coefficients model this type of distortion.

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 your calibration accuracy, select Export Camera Parameters. You can either save and export the camera parameters to an object in the MATLAB workspace, or generate the camera parameters as a MATLAB script.

 Export Camera Parameters

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 its distortion coefficients. You can use this object for various computer vision tasks, such as image undistortion, measuring planar objects, and 3-D reconstruction. For more information on measuring planar objects, 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 Export estimation errors.

 Generate MATLAB Script

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.

Note

You cannot generate a MATLAB script for custom pattern camera parameters defined using the vision.calibration.PatternDetector class.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3