Skip to content

Commit bdf6f02

Browse files
author
Ilya Lysenkov
committed
Changed the camera calibration sample to support circles' grid pattern
1 parent 5f5dc91 commit bdf6f02

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

samples/cpp/calibration.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void help()
4747
"Usage: calibration\n"
4848
" -w <board_width> # the number of inner corners per one of board dimension\n"
4949
" -h <board_height> # the number of inner corners per another board dimension\n"
50+
" [-pt <pattern>] # the type of pattern: chessboard or circles' grid\n"
5051
" [-n <number_of_frames>] # the number of frames to use for calibration\n"
5152
" # (if not specified, it will be set to the number\n"
5253
" # of board views actually available)\n"
@@ -74,6 +75,7 @@ void help()
7475
}
7576

7677
enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 };
78+
enum Pattern { CHESSBOARD, CIRCLESGRID };
7779

7880
static double computeReprojectionErrors(
7981
const vector<vector<Point3f> >& objectPoints,
@@ -288,6 +290,7 @@ int main( int argc, char** argv )
288290
int cameraId = 0;
289291
vector<vector<Point2f> > imagePoints;
290292
vector<string> imageList;
293+
Pattern pattern = CHESSBOARD;
291294

292295
if( argc < 2 )
293296
{
@@ -308,6 +311,15 @@ int main( int argc, char** argv )
308311
if( sscanf( argv[++i], "%u", &boardSize.height ) != 1 || boardSize.height <= 0 )
309312
return fprintf( stderr, "Invalid board height\n" ), -1;
310313
}
314+
else if( strcmp( s, "-pt" ) == 0 )
315+
{
316+
if( !strcmp( argv[++i], "circles" ) )
317+
pattern = CIRCLESGRID;
318+
else if( !strcmp( argv[++i], "chessboard" ) )
319+
pattern = CHESSBOARD;
320+
else
321+
return fprintf( stderr, "Invalid pattern type: must be chessboard or circles\n" ), -1;
322+
}
311323
else if( strcmp( s, "-s" ) == 0 )
312324
{
313325
if( sscanf( argv[++i], "%f", &squareSize ) != 1 || squareSize <= 0 )
@@ -425,11 +437,22 @@ int main( int argc, char** argv )
425437
vector<Point2f> pointbuf;
426438
cvtColor(view, viewGray, CV_BGR2GRAY);
427439

428-
bool found = findChessboardCorners( view, boardSize, pointbuf,
429-
CV_CALIB_CB_ADAPTIVE_THRESH & CV_CALIB_CB_FAST_CHECK & CV_CALIB_CB_NORMALIZE_IMAGE);
440+
bool found;
441+
switch( pattern )
442+
{
443+
case CHESSBOARD:
444+
found = findChessboardCorners( view, boardSize, pointbuf,
445+
CV_CALIB_CB_ADAPTIVE_THRESH & CV_CALIB_CB_FAST_CHECK & CV_CALIB_CB_NORMALIZE_IMAGE);
446+
break;
447+
case CIRCLESGRID:
448+
found = findCirclesGrid( view, boardSize, pointbuf );
449+
break;
450+
default:
451+
return fprintf( stderr, "Unknown pattern type\n" ), -1;
452+
}
430453

431454
// improve the found corners' coordinate accuracy
432-
if(found) cornerSubPix( viewGray, pointbuf, Size(11,11),
455+
if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(11,11),
433456
Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
434457

435458
if( mode == CAPTURING && found &&

0 commit comments

Comments
 (0)