Camera Calibration

From EMGU
Revision as of 14:09, 12 November 2012 by Chris Johnson (talk | contribs) (Camera Calibration: Save)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Camera Calibration

Namespace

Emgu.CV.CameraCalibration

References

EMGU Reference
OpenCV Reference
OpenCV Use Reference
Opencv Tutorial

Downloads

Source Code V1.0

Example

The following example show the use of the camera calibration function within EMGU. The function of this library is to allow to automatic calibrate of a cameras FOV. When wide angle 'fisheye' lenses are used in photography a curvature effect can be observed. This type of lens maximises the FOV and is commonly seen in pin-hole camera. The following example shows the the use of the CameraCalibration class in correcting this error. The same class can also be used for producing distortion filters if required.


Camera Calibration

BeforeAfter


Camera Distortion

BeforeAfter


Software

Before

Pre-Requisites

The code provided should run straight out of the Emgu.Example folder (V2.4.2), extract it to this location. If the code fails to execute re-reference the EMGU libraries and include the required opencv dlls in the bin directory. Note that the project is set to build to the output path "..\..\..\bin\" you may wish to change this if you don't extract to the EMGU.Example folder.

EMGU Coding Level:While the coding is not advanced the rated level for this example is Intermediate. This is not designed as a beginners tutorial and general knowledge of the EMGU video capture example is expected.

To run calibration you will require a chess board. There is one available here (,pdf) (or png here), print this out and place it onto a flat surface. If you want to generate a distortion filter place it onto a curved surface or try one of the pre filtered chessboard, Filter Chessboard 1, Filter Chessboard 2.


The Code

The code provided in this sample is basic there is little or no error checking. Support is available through the Forums but please try and examine the code before saying it doesn't work for you. The code is not optimised instead is better formatted to provided an understanding of the stages involved.

Camera Calibration works by producing a scene view, formed by projecting 3D points into the image plane using a perspective transformation more informations is available here and here.

To initiate the correction routine fill in the variables and select to go button. This will be re-enabled once the set number of frames has been acquired. The image will initially display the tracked points from the chessboard so you can observe it's ability before calibration.


The Code: Variables

Setting of the chessboard size is achieved using width and heigh variables try playing with these and with a larger chessboard to see what effects they have on calibration.

const int width = 9;//9 //width of chessboard no. squares in width - 1
const int height = 6;//6 // heght of chess board no. squares in heigth - 1
Size patternSize = new Size(width, height); //size of chess board to be detected


These buffers store the relevant information for calculating the calibration there default is set to 100 by the image buffer. This is overwritten by the software remember the larger the value the longer it will take to calculate it will have to deal with 100*(9*6)=5400 point relations if the current maximum buffer size is used.


<syntaxhighlight lang="csharp"> Bgr[] line_colour_array = new Bgr[width * height]; // just for displaying coloured lines of detected chessboard static Image<Gray, Byte>