26 cerr <<
"usage:\n" << s
27 <<
"[<cam number>|<video file>] [-m <model image>] [-r]\n"
28 " -m specifies model image\n"
29 " -r do not load cached model image\n";
33 int main(
int argc,
char** argv )
35 CvCapture* capture = 0;
37 const char *captureSrc =
"0";
41 for (
int i=1; i<argc; i++) {
42 if (strcmp(argv[i],
"-m") ==0) {
43 if (i==argc-1)
usage(argv[0]);
46 }
else if (strcmp(argv[i],
"-r")==0) {
48 }
else if (argv[i][0]==
'-') {
55 if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
56 capture = cvCaptureFromCAM( captureSrc[0]-
'0');
58 capture = cvCaptureFromAVI( captureSrc );
62 cerr <<
"Could not initialize capturing from " << captureSrc <<
" ...\n";
86 detector.
build(shot, 400, 32, 3, 16, 3);
88 cvReleaseImage(&shot);
95 const char *win =
"Bazar";
100 cvNamedWindow(win, 0);
104 IplImage* frame = cvQueryFrame(capture);
105 calib.
AddCamera(frame->width, frame->height);
111 frame = cvQueryFrame( capture );
116 if (frame->nChannels >1) {
118 gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
119 cvCvtColor(frame, gray, CV_RGB2GRAY);
125 if (detector.
detect(gray)) {
128 cout << nbHomography <<
" homographies.\n";
129 if (nbHomography >=70) {
150 cvShowImage(win, display);
153 if( cvWaitKey(10) >= 0 )
157 cvReleaseCapture( &capture );
158 cvDestroyWindow(win);
165 if (*dst==0) *dst=cvCloneImage(video);
166 else cvCopy(video, *dst);
178 3, CV_RGB(0,255,0), -1, 8,0);
184 static void putText(IplImage *im,
const char *text, CvPoint p, CvFont *f1, CvFont *f2)
186 cvPutText(im,text,p,f2, cvScalarAll(0));
187 cvPutText(im,text,p,f1, cvScalarAll(255));
193 const char *win =
"Bazar";
195 CvFont font, fontbold;
197 cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1, 1);
198 cvInitFont( &fontbold, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 5);
200 cvNamedWindow(win, 0);
204 IplImage *shot=0, *text=0;
206 bool accepted =
false;
210 frame = cvQueryFrame(capture);
211 if (!text) text=cvCloneImage(frame);
212 else cvCopy(frame,text);
213 putText(text,
"Please take a frontal view of a",
cvPoint(3,20), &font, &fontbold);
214 putText(text,
"textured planar surface and press space",
cvPoint(3,40), &font, &fontbold);
215 cvShowImage(win, text);
218 char k = cvWaitKey(pause ? 0 : 10);
220 case 'n': pause=
false;
break;
224 if (shot) cvCopy(frame,shot);
225 else shot = cvCloneImage(frame);
228 cvShowImage(win, text);
232 case '\n':
if (pause && shot) accepted=
true;
break;
233 case 'q': exit(0);
break;
235 default: cerr << k <<
": what?\n";
239 cvReleaseImage(&text);
245 static std::vector<CamCalibration::s_struct_points> pts;