OpenCV 2.46 Calibration example source code (using calibrateCamera function)

This is advanced from "http://feelmare.blogspot.kr/2011/08/camera-calibration-using-pattern-image.html"



When you run the calibration example source code, some information will ask you.
First question is to ask number of width corner points.
Second question is to ask number of height corner points.
Third question is to ask number of pattern boards.


Because I use this chess board pattern, the answers is as follows


Of course, you have to prepare the captured images of chess pattern.

The source code detect corner points and calibration will be performed.
This function 'findChessboardCorners' is used to detection corners.
And 'calibrateCamera' function is used to get calibration parameters.

This is calibration example source code.


//code start

//code end


After calibration, the source code save ->
distortion_coeffs.txt
intrinsic.txt
rotation.txt
translatioin.txt
imagept.txt
objectpt.txt

and

The result images of corner detected.














This is matlab source code.
To confirm the result of calibration, I draw 2D image coordinate point to the 3D space.

m=[R|t]M or m=[R|-Rc]M
m is camera origin axis based coordinate.
M is world origin axis based coordinate.
In the -Rc, c is translate vector based on world origin axis.

pattern axis based
The equation is like this
R'(m-t)=M
In the equation, m is camera line coordinate for drawing.
M is camera coordinate based on pattern axis.


camera axis based, pattern position in 3D
The equation is like this
m=R*M+t or m=[R|t]M
In the equation, M is pattern coordinate for example -> [0 0 0; 10, 0 0; 0 10 0; 10 10 0] or 
R is rotation 3x3 matrix, t is 3x1 translation matrix.
After calibration, we can get each R,t of pattern boards.
m is pattern 3D coordinate based on camera origin axis. 


The main m file is Sapce2D3D.m in matlab files.

//matlab code start

//matlab code end
You can download calibration source code and matlab code in here.




Pattern Image for Camera Calibration


[ Download Pattern.pdf ]

Camera calibration using pattern image / C++ source (OpenCV) / 패턴 그림을 이용한 카메라 캘리브레이션 소스




Created Date : 2008.11
Language : C/C++
Tool : Microsoft Visual C++
Library & Utilized : OpenCV 1.0
Reference : Learning OpenCV Book


I made Camera calibration source for my convenience using the book that is "Learning OpenCV".
First of all, prepare several pattern images. And make same file name with ordered index.
Ex) pattern1.jpg, pattern2.jpg, pattern3.jpg ...
And answer the some questions.

Pattern width box count(black box number), height box count, the number of image
and file path and file name. Then point extraction is processed.

After all processing, below file is saved in the folder that is same location as images.

Distortion.xml
Distortion.txt
intrinsic.xml
intrinsic_matrix.txt
rotation_matricex.txt
rotation_matricex.xml
translation_matrices.txt
translation_matrices.xml

The points of each pattern image is saved as below file names.
pattern1.txt, pattern2.txt, pattern3.txt......

This source uses 'cvFindChessboardCorners' and 'cvFindCornerSubPix' functions for detecting pattern point. And for drawing, 'cvDrawChessboardCorners' function is used. 'cvCalibrateCamera2' is used for calibration.

This code is programed by Microsoft Visual studio 6.0 and OpenCV 1.0 Lib.
All OpenCv 1.0 dlls are included in the zip file.

You can download heare - > < entire source >

If you have any progressive agenda, Plz give me using reply.
Thank you.


(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)

------------------------------------------------------------------------------




OpenCV를 이용한 카메라 캘리브레이션(캡쳐된 이미지를 이용함)

체스 보드 패턴의 교정판을 사용함
프로그램 실행후
패턴의 가로, 세로 점 개수 입력
패턴의 경로 입력 (예: ./p1/image)
패턴의 개수 입력 (10으로 입력하면 ./p1/image1.jpg ./p1/image2.jpg ... ./p1/image10.jpg)

이미지 한 장씩 교정점을 찾는다.
교정점을 제대로 찾지 못한 이미지는 실패로 간주하고 사용하지 않는다.
입력된 이미지를 모두 다 처리한 후
Zhang's 캘리브레이션을 수행
콘솔 창에 내부 파라미터 Instrinsic Matrirx와 왜곡 계수 Distortion Vector 값을 출력 해주고
또한 각각을 xml 파일로 저장한다.
그리고 각 패턴에 대한 Rotion 과 Translation Matrix 또한 콘솔 창에 출력하고 xml파일로 저장한다.

저장된 Instrinsic parameter, distortion coffecient를 이용하여 어플리케이션 구현이 가능하다.

체스보드에서 교정점을 찾는 방법은
cvFindChessboardCorners, cvFindCornerSubPix 함수를 이용하였으며
찾은 교정점을 그려주는 함수는 cvDrawChessboardCorners를 이용
캘리브레이션은 cvCalibrateCamera2 함수를 이용함


본 소스는 microsoft visual studio 6.0, opencv 1.0을 이용하여 만든 소스입니다.

여기서 다운 받을수 있습니다. - > < entire source >