Camera calibration and correction based on EMGUCV

Source: Internet
Author: User

Tags: EMGUCV camera calibration C #2015-05-03 14:55 501 people read comments (6) favorite reports Category: C #

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

Objective

Before with OPENCV camera calibration and correction, now platform for, instead of C #, with EMGUCV do, in fact, is OpenCV C # version.

In EMGUCV, there are two classes of camera calibration, one is the Cvinvoke class, the other is the Cameracalibration class, the two kinds of calibration effect is similar, but the cvinvoke involved in most of the functions are pointer type, and C # for pointer operation is more troublesome. In this paper, the camera calibration is done on the basis of Cameracalibration class, and the corrected image is completed by Cvinvoke class.

Function Description 1, corner detection

[CSharp]View Plaincopy print?
    1. Public Static pointf[] Findchessboardcorners (
    2. Image<gray, byte> image,
    3. Size Patternsize,
    4. Calib_cb_type Flags
    5. )

Parameters

Image
Type:emgu.cv.image<gray, Byte>source chessboard view
Patternsize
Type:System.Drawing.SizeThe number of
inner corners per chessboard row and column
flog=
Type:Emgu.CV.CvEnum.CALIB_CB_TYPEVarious Operation Flags

Return Value

Type:pointf[]the Corners detected If the chess board pattern is found, otherwise null is returned

Note: The input image needs to be grayscale, before the detection of corner points need to open up space, such as:

[CSharp]View Plaincopy print?
    1. cornersdetected = new pointf[npoints]; //npoints represents the total number of corner points for a single image
    2. cornersdetected = Cameracalibration.findchessboardcorners (Chessboardimage, Patternsize,
    3. Calib_cb_type. Adaptive_thresh | Calib_cb_type. Normalize_image);

2. Calibration function [CSharp]View Plaincopy print?
    1. Public static double Calibratecamera (
    2. Mcvpoint3d32f[][] Objectpoints,
    3. Pointf[][] Imagepoints,
    4. Size ImageSize,
    5. Intrinsiccameraparameters Intrinsicparam,
    6. Calib_type Calibrationtype,
    7. Mcvtermcriteria Termcriteria,
    8. Out extrinsiccameraparameters[] Extrinsicparams
    9. )

Parameters

Objectpoints
type:emgu.cv.structure.mcvpoint3d32f[][]the 3D Location of the object points. The first index is the index of an image, second index is the index of the
Imagepoints
Type:System.Drawing . ::.. PointF[][]the 2D image location of the points. The first index is the index of the image, second index is the index of the
ImageSize
Type:System.Drawing.SizeThe size of the image, used only to initialize intrinsic camera matrix
Intrinsicparam
Type:Emgu.CV.IntrinsicCameraParametersThe intrisinc parameters, might contains some initial values. The values would be modified by this function.
Calibrationtype
Type:Emgu.CV.CvEnum . Calib_typeccalibration TYPE
Termcriteria
Type:Emgu.CV.Structure . McvtermcriteriaThe termination criteria
Extrinsicparams
Type:Emgu.CV . Extrinsiccameraparameters[]the output array of extrinsic parameters.

Return Value

Type:doublethe Final Reprojection Error Note: objectpoints represents the coordinates of the checkerboard corner in the world coordinate system, and how many checkerboard images should have a set of corner coordinates, in physical dimensions. Imagepoints represents the coordinates of the corner point in the image, in pixels. The return value is a re-projection error.

3, mapping matrix to find [CSharp]View Plaincopy print?
    1. Public static void Cvinitundistortmap (
    2. IntPtr Intrinsicmatrix,
    3. IntPtr Distortioncoeffs,
    4. IntPtr MAPX,
    5. IntPtr mapy
    6. )

Parameters

Intrinsicmatrix
Type:System.IntPtrThe camera Matrix (A) [FX 0 cx; 0 FY cy; 0 0 1]
Distortioncoeffs
Type:System.ntPtrThe vector of distortion coefficients, 4x1 or 1x4 [K1, K2, p1, p2].
Mapx
Type:System.IntPtrThe Output Array of x-coordinates
of the map
Mapy
type:system . NtptrThe output array of y-coordinates
of the map
Note: Defines a mapping matrix variable for the matrix class whose properties contain PTR and can be used directly as pointers, such as:

[CSharp]View Plaincopy print?
    1. Private matrix<float> mapx = new matrix<float> (height, width);
    2. Private matrix<float> mapy = new matrix<float> (height, width);

4. Geometric transformation

[CSharp]View Plaincopy print?
    1. public static void Cvremap (
    2. IntPtr SRC,
    3. INTPTR DST,
    4. IntPtr MAPX,
    5. IntPtr Mapy,
    6. int flags,
    7. Mcvscalar Fillval
    8. )

Parameters

Src
Type:System.ntPtr
Source Image
Dst
Type:System.IntPtr
Destination Image
Mapx
Type:System.IntPtr
The map of X-coordinates (32fc1 image)
Mapy
Type:system . Ntptr
The map of Y-coordinates (32fc1 image)
flog=
Type:System.Int32
A combination of interpolation method and the optional flag cv_warp_fill_outliers
Fillval
Type:Emgu.CV.Structure.MCvScalar
A value used to fill outliers
Note: Flags defines the WARP enumeration type under Cvenum, called: (int) WARP. Cv_warp_inverse_map

Program Description

The software interface based on EMGUCV camera calibration and correction is as follows:

, the interface contains checkerboard information settings, calibration and corrective event implementation, and so on.

Image comparison before and after correction:

The code implements reading the checkerboard image from the camera or reading the image locally, the number of images is imges specified, the checkerboard size is specified by square size, then the camera calibration is successfully detected, the corner value and the camera parameters are saved, and the distortion correction function is achieved by the Rectify button. To avoid detecting corner points for each calibration, set the Read Corners button, read corner points (including objectpoints and imagepoints), and start calibrate to achieve calibration. All data is saved to an XML file for easy viewing and extraction.

Camera calibration and correction based on EMGUCV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.