24 cerr <<
"usage:\n" << s
25 <<
"[<cam number>|<video file>] [-m <model image>]\n";
29 int main(
int argc,
char** argv )
31 CvCapture* capture = 0;
33 const char *captureSrc =
"0";
36 for (
int i=1; i<argc; i++) {
37 if (strcmp(argv[i],
"-m") ==0) {
38 if (i==argc-1)
usage(argv[0]);
41 }
else if (argv[i][0]==
'-') {
48 if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
49 capture = cvCaptureFromCAM( captureSrc[0]-
'0');
51 capture = cvCaptureFromAVI( captureSrc );
55 cerr <<
"Could not initialize capturing from " << captureSrc <<
" ...\n";
77 cerr <<
"Unable to load the model image "
86 const char *win =
"Bazar";
91 cvNamedWindow(win, 0);
96 cerr <<
"Unable to load calibration data\n";
103 IplImage *frame = cvQueryFrame( capture );
108 if (frame->nChannels >1) {
110 gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
111 cvCvtColor(frame, gray, CV_RGB2GRAY);
117 if (detector.
detect(gray)) {
127 cvShowImage(win,display);
129 cvShowImage(win, frame);
133 if( cvWaitKey(10) >= 0 )
137 cvReleaseCapture( &capture );
138 cvDestroyWindow(win);
145 if (*dst==0) *dst=cvCloneImage(video);
146 else cvCopy(video, *dst);
151 double w =video->width/2.0;
152 double h =video->height/2.0;
161 double projected[3][4];
162 CvMat ptsMat, projectedMat;
163 cvInitMatHeader(&ptsMat, 4, 4, CV_64FC1, pts);
164 cvInitMatHeader(&projectedMat, 3, 4, CV_64FC1, projected);
167 cvGEMM(m, &ptsMat, 1, 0, 0, &projectedMat, CV_GEMM_B_T );
168 for (
int i=0; i<4; i++) {
169 projected[0][i] /= projected[2][i];
170 projected[1][i] /= projected[2][i];
174 cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
175 cvPoint((
int)projected[0][1], (
int)projected[1][1]), CV_RGB(0,255,0));
176 cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
177 cvPoint((
int)projected[0][2], (
int)projected[1][2]), CV_RGB(255,0,0));
178 cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
179 cvPoint((
int)projected[0][3], (
int)projected[1][3]), CV_RGB(0,0,255));
187 static std::vector<CamCalibration::s_struct_points> pts;