12 #include <sys/timeb.h>
26 cerr <<
"usage:\n" << s
27 <<
"[<cam number>|<video file>] [-m <model image>]\n";
31 int main(
int argc,
char** argv )
33 CvCapture* capture = 0;
37 const char *captureSrc =
"0";
40 for (
int i=1; i<argc; i++) {
41 if (strcmp(argv[i],
"-m") ==0) {
42 if (i==argc-1)
usage(argv[0]);
45 }
else if (argv[i][0]==
'-') {
52 if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
53 capture = cvCaptureFromCAM( captureSrc[0]-
'0');
55 capture = cvCaptureFromAVI( captureSrc );
59 cerr <<
"Could not initialize capturing from " << captureSrc <<
" ...\n";
63 cout <<
"Instructions:\n"
64 " 1 - present a textured planar object to the camera. \n"
65 " 2 - push space to freeze the image\n"
66 " 3 - if the frozen image makes a good model image, press 'y'.\n"
67 " Otherwise, press space to restart the video and take another shot. \n";
91 const char *win =
"Bazar";
96 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
99 struct timeb last, now;
102 struct timeval last, now;
103 gettimeofday(&last,0);
113 frame = cvQueryFrame( capture );
118 if (frame->nChannels >1) {
120 gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
121 cvCvtColor(frame, gray, CV_RGB2GRAY);
127 if (detector.
detect(gray)) {
130 cvShowImage(win, display);
140 duration = ( double(( now.time-last.time ) * 1e4)
141 + double( now.millitm-last.millitm ) ) / 1e4;
143 gettimeofday(&now,0);
144 duration = double(now.tv_sec-last.tv_sec)
145 + double(now.tv_usec-last.tv_usec)/1e6;
150 cout <<
"FPS: " << 5.0/duration << endl;
155 if( cvWaitKey(1) >= 0 )
159 cvReleaseCapture( &capture );
160 cvDestroyWindow(win);
167 if (*dst==0) *dst=cvCloneImage(video);
168 else cvCopy(video, *dst);
180 3, CV_RGB(0,255,0), -1, 8,0);
189 const char *win =
"Bazar";
191 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
197 bool accepted =
false;
201 frame = cvQueryFrame(capture);
202 cvShowImage(win, frame);
205 int k = cvWaitKey(pause ? 50 : 1);
210 if (shot) cvCopy(frame,shot);
211 else shot = cvCloneImage(frame);
212 cvShowImage(win, shot);
216 case '\n':
if (pause && shot) accepted=
true;
break;
217 case 'q': exit(0);
break;
222 detector.
build(shot, 400, 32, 3, 16, 3);
224 cvReleaseImage(&shot);