This interactive example shows how compute the geometric calibration of a single camera.
#include <iostream>
#include "cv.h"
#include "highgui.h"
#ifdef HAVE_CONFIG_H
#endif
void usage(
const char *s) {
cerr << "usage:\n" << s
<< "[<cam number>|<video file>] [-m <model image>] [-r]\n"
" -m specifies model image\n"
" -r do not load cached model image\n";
exit(1);
}
int main(
int argc,
char** argv )
{
CvCapture* capture = 0;
const char *captureSrc = "0";
bool relearn=false;
for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "-m") ==0) {
if (i==argc-1)
usage(argv[0]);
i++;
} else if (strcmp(argv[i], "-r")==0) {
relearn=true;
} else if (argv[i][0]=='-') {
} else {
captureSrc = argv[i];
}
}
if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
capture = cvCaptureFromCAM( captureSrc[0]-'0');
else
capture = cvCaptureFromAVI( captureSrc );
if( !capture )
{
cerr <<"Could not initialize capturing from " << captureSrc << " ...\n";
return -1;
}
400,
32,
3,
16,
3
))
{
detector.
build(shot, 400, 32, 3, 16, 3);
cvReleaseImage(&shot);
}
const char *win = "Bazar";
IplImage* display=0;
IplImage*gray=0;
cvNamedWindow(win, 0);
IplImage* frame = cvQueryFrame(capture);
calib.
AddCamera(frame->width, frame->height);
int nbHomography =0;
for(;;)
{
frame = cvQueryFrame( capture );
if( !frame )
break;
if (frame->nChannels >1) {
if( !gray )
gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
cvCvtColor(frame, gray, CV_RGB2GRAY);
} else {
gray = frame;
}
nbHomography++;
cout << nbHomography << " homographies.\n";
if (nbHomography >=70) {
50,
2,
3,
3,
0,
0,
0.0078125,
0.9,
0.001953125,
12,
0.05,
3
)) {
break;
}
}
}
cvShowImage(win, display);
if( cvWaitKey(10) >= 0 )
break;
}
cvReleaseCapture( &capture );
cvDestroyWindow(win);
return 0;
}
{
if (*dst==0) *dst=cvCloneImage(video);
else cvCopy(video, *dst);
cvCircle(*dst,
3, CV_RGB(0,255,0), -1, 8,0);
}
}
}
}
static void putText(IplImage *im,
const char *text, CvPoint p, CvFont *f1, CvFont *f2)
{
cvPutText(im,text,p,f2, cvScalarAll(0));
cvPutText(im,text,p,f1, cvScalarAll(255));
}
{
const char *win = "Bazar";
CvFont font, fontbold;
cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1, 1);
cvInitFont( &fontbold, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 5);
cvNamedWindow(win, 0);
bool pause=false;
IplImage *frame;
IplImage *shot=0, *text=0;
bool accepted =false;
while (!accepted) {
if (!pause) {
frame = cvQueryFrame(capture);
if (!text) text=cvCloneImage(frame);
else cvCopy(frame,text);
putText(text,
"Please take a frontal view of a",
cvPoint(3,20), &font, &fontbold);
putText(text,
"textured planar surface and press space",
cvPoint(3,40), &font, &fontbold);
cvShowImage(win, text);
}
char k = cvWaitKey(pause ? 0 : 10);
switch (k) {
case 'n': pause=false; break;
case ' ':
pause = !pause;
if (pause) {
if (shot) cvCopy(frame,shot);
else shot = cvCloneImage(frame);
cvCopy(shot,text);
cvShowImage(win, text);
}
break;
case 'y':
case '\n': if (pause && shot) accepted=true; break;
case 'q': exit(0); break;
case -1: break;
default: cerr << k << ": what?\n";
}
}
cvReleaseImage(&text);
return shot;
}
{
static std::vector<CamCalibration::s_struct_points> pts;
pts.clear();
}
}
}