Camera calibration - correction of distortion

Studies done before the camera calibration, but now forgotten a lot, yesterday afternoon to pick it up, a good review about the (primarily a book to learn opencv content).

Camera calibration basics:

Camera calibration error comprises internal reference (4), distortion parameters (radial and tangential to the common 5), the outer parameters (translation and rotation of 6).

Error Analysis Parameters: pinhole camera model using the model imaging model, since the center shaft mounting problems, which resulted in a precision error, the so-called camera parameters errors, using a 3X3 matrix represented by (A) [fx 0 cx; 0 fy . cy; 0 0 1], there are four unknown parameters; in addition, because the pinhole imaging light efficiency is not high, the use of a lens, which caused distortion error:

Radial distortion: congenital lens CAUSE This is because the condition (lens shape), the distortion imager center (optical center) is 0, with the movement to the edge, the more severe distortion. There are three parameters, k1, k2, k3 where k3 is an optional parameter.

Tangential distortion: This is caused by the installation of the camera, such as when the lens is not perfectly parallel to the image plane generated.

Rotation and translation for the outer main parameters, the angle of rotation and three translation parameters in three directions 6.

The board is not introduced. Mainly extracting corner points, to facilitate later calculation, OpenCV function has function. p423 has introduced the principle of the book, interested friends can reference content.

The main function opencv introduction and implementation process:

1. First, get the data source (video or image), a chronicle of her recorded video I read;

2. Initialize the single frame board data, such as 6X4, and extraction operation board corners;

Function used Description: 

CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
                                    CvPoint2D32f* corners,
                                    int* corner_count CV_DEFAULT(NULL),
                                    int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );

This functional interior angle to find the point:

  • image

  • FIG input board, must be an 8-bit grayscale or color images.

  • pattern_size

  • FIG checkerboard number per row and each column corner point.

  • corners

  • Detecting the corner points

  • corner_count

  • Output, the number of corner points. If it is not NULL, the function of the detected corner points to the number stored in this variable.

  • flags

  • Various operations flag may be 0 or a combination of the following values:

    • CV_CALIB_CB_ADAPTIVE_THRESH - use of adaptive threshold (calculated by the average luminance of the image) is converted into black and white image, rather than a fixed threshold.

    • CV_CALIB_CB_NORMALIZE_IMAGE - prior to binarization using a fixed threshold or an adaptive threshold to use to equalize image brightness cvNormalizeHist.

    • CV_CALIB_CB_FILTER_QUADS - other criteria (such as contour, area, perimeter, a square shape) to remove the error block detected in the contour detecting stage.

void cvFindCornerSubPix(const CvArr* image,CvPoint2D32f* corners,int count,CvSize win,CvSize zero_zone,CvTermCriteria criteria)
Function to find cvFindCornerSubPix corner positions with subpixel precision iteratively:

image

Input image must be 8-bit grayscale or color images.

corners

Initial coordinate point input angle, but also stores coordinates accurate output.

count

The number of corners

win

Half the size of the search window. If the win = (5,5) then using (5 * 2 + 1) × (5 * 2 + 1) = 11 × 11 search window size

zero_zone

Half the size of the dead zone, the dead zone area to do the summation of the central location does not search area. It is used to avoid certain possible singularities of the autocorrelation matrix appears. When the value (-1, -1) indicates no dead zone.

criteria

Termination condition of the iterative process seeking corner point. I.e., determining the angular position of either the number of iterations is greater than a set value, or precisely understand reaches a set value. criteria may be the maximum number of iterations, or the accuracy of the setting, or may be a combination thereof.

3. The camera calibration parameters demand, we are currently seeking internal control and distortion parameters for image correction;

Function used Description:
void cvCalibrateCamera2( const CvMat* object_points, const CvMat* image_points, const CvMat*point_counts, CvSize image_size, CvMat* intrinsic_matrix, CvMat* distortion_coeffs, CvMat* rotation_vectors=NULL, CvMat* translation_vectors=NULL, int flags=0 );

Calibration function, internal control and external demand camera parameters:

  • object_points

  • Punctuation given world coordinates for 3xN or Nx3 matrix, where N is the total number of all the mid-point of view.

  • image_points

  • Image coordinate calibration points, or 2xN Nx2 matrix, where N is the total number of all views midpoint.

  • point_counts

  • Vector, the number of points specified in the different views, or I xM Mx1 vector, M is the number of views.

  • image_size

  • Image size, only in the initialization parameters.

  • intrinsic_matrix

  • Internal reference output matrix (A), if the specified CV_CALIB_USE_INTRINSIC_GUESS and (or) CV_CALIB_FIX_ASPECT_RATION, fx, fy, cx and cy some or all must be initialized.

  • distortion_coeffs

  • It outputs a vector of size of 4x1 or 1x4, which is the deformation parameter [k1, k2, p1, p2].

  • rotation_vectors

  • An output size of 3xM Mx3 or matrix, which is the rotation vector (compact representation of the rotation matrix, specific reference function cvRodrigues2)

  • translation_vectors

  • An output size of 3xM Mx3 or matrix, which is a translation vector.

  • flags

  • Different flags, may be 0, or a combination of the following values:

    • CV_CALIB_USE_INTRINSIC_GUESS - the initial value of the parameter matrix contains fx, fy, cx and cy of. Otherwise, (cx, cy) is initialized to the center of the image (image size used here), the focal length difference is calculated by least square method. Note that if the internal parameters are known, it is not necessary to use this function, you can use cvFindExtrinsicCameraParams2.

    • CV_CALIB_FIX_PRINCIPAL_POINT - the principal point of change in the global optimization process, has been in the central position or another designated position (when provided CV_CALIB_USE_INTRINSIC_GUESS).

    • CV_CALIB_FIX_ASPECT_RATIO - optimization process considered fx and fy only one independent variable, keeping the ratio fx / fy unchanged, with the same value when the value of the parameter within the matrix initialization fx / fy of. In this case, (fx, fy), or the initial value of the actual read from the input memory matrix (when CV_CALIB_USE_INTRINSIC_GUESS is specified), or using the estimated value (the latter case fx and fy may be set to any value, only ratio is used).

    • CV_CALIB_ZERO_TANGENT_DIST - cut is set to 0 to deformation parameter (p1, p2), the value 0 is held in the optimization process.

4. The correction of the image using the corrected parameters obtained on step.

Function descriptions used, there are two ways to correct, are the following introduction:

a. Using cvInitUndistortMap () and cvRemap () to process the former is used to calculate the distortion map, which is applied to the obtained map image.

void cvInitUndistortMap( const CvMat* intrinsic_matrix, const CvMat* distortion_coeffs, CvArr* mapx, CvArr* mapy );
This function computes the distortion map, wherein the camera parameters intrinsic_matrix matrix (A) [fx 0 cx; 0 fy cy; 0 0 1] .distortion_coeffs deformation coefficient vector [k1, k2, p1, p2, k3], a size of 5x1 or 1x5 . mapx matrix corresponding to the x coordinate. mapy matrix corresponding to the y coordinate.
void cvRemap( const CvArr* src, CvArr* dst,const CvArr* mapx, const CvArr* mapy,int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,CvScalar fillval=cvScalarAll(0) );

Common geometric transformation of image, image correction is obtained:

     the src 
     . input image 
dst 
output image. 
  MapX 
X coordinate mapping (32fC1 Image). 
mapy 
Y coordinates map (32fC1 Image). 
the flags 
combination interpolation method and the following switch options: 
  CV_WARP_FILL_OUTLIERS - pixel outside the hatch boundary if the output image. portion of the pixel fall outside the boundary of the converted, then their value is set to fillval.

A correct image coordinates of each pixel in the image where the strain - cvInitUndistortMap function corresponding to the non-deformation previously calculated. This can be passed to the corresponding function cvRemap (together with the input and output images).

b. Use cvUndistort2 () function at once in all matters, is not recommended.

CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
  const CvMat* camera_matrix,
  const CvMat* distortion_coeffs,
  const CvMat* new_camera_matrix CV_DEFAULT(0) );

Function Description:

    Where, src input image, dst an output image, the camera_matrix camera parameter matrix (A) [fx 0 cx; 0 fy cy; 0 0 1], distortion_coeffs deformation coefficient vector [k1, k2, p1, p2, k3] , the size of 5x1 or 1x5.

The first recommendation is to use an algorithm to calculate because of the distortion mapping is a time-consuming operation, when the constant distortion map, use the first higher efficiency.

I experiment results are as follows:

        
                                               

The code here is not left, opencv has a similar source, a friend in need leave contact information can be sent to you, encourage each other!

Guess you like

Origin www.cnblogs.com/wwwbdabc/p/11653254.html