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?
- Public Static pointf[] Findchessboardcorners (
- Image<gray, byte> image,
- Size Patternsize,
- Calib_cb_type Flags
- )
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?
- cornersdetected = new pointf[npoints]; //npoints represents the total number of corner points for a single image
- cornersdetected = Cameracalibration.findchessboardcorners (Chessboardimage, Patternsize,
- Calib_cb_type. Adaptive_thresh | Calib_cb_type. Normalize_image);
2. Calibration function
[CSharp]View Plaincopy print?
- Public static double Calibratecamera (
- Mcvpoint3d32f[][] Objectpoints,
- Pointf[][] Imagepoints,
- Size ImageSize,
- Intrinsiccameraparameters Intrinsicparam,
- Calib_type Calibrationtype,
- Mcvtermcriteria Termcriteria,
- Out extrinsiccameraparameters[] Extrinsicparams
- )
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?
- Public static void Cvinitundistortmap (
- IntPtr Intrinsicmatrix,
- IntPtr Distortioncoeffs,
- IntPtr MAPX,
- IntPtr mapy
- )
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?
- Private matrix<float> mapx = new matrix<float> (height, width);
- Private matrix<float> mapy = new matrix<float> (height, width);
4. Geometric transformation
[CSharp]View Plaincopy print?
- public static void Cvremap (
- IntPtr SRC,
- INTPTR DST,
- IntPtr MAPX,
- IntPtr Mapy,
- int flags,
- Mcvscalar Fillval
- )
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