27 int nbImages,
bool cache);
30 cerr <<
"usage:\n" << s
31 <<
"[<cam number>|<video file>] [-m <model image>] [-r]\n"
32 " -m specifies model image\n"
33 " -r do not load any data\n"
34 " -t train a new classifier\n"
35 " -g recompute geometric calibration\n"
36 " -l rebuild irradiance map from scratch\n";
40 int main(
int argc,
char** argv )
42 CvCapture* capture = 0;
44 const char *captureSrc =
"0";
46 bool redo_training=
false;
47 bool redo_lighting=
false;
51 for (
int i=1; i<argc; i++) {
52 if (strcmp(argv[i],
"-m") ==0) {
53 if (i==argc-1)
usage(argv[0]);
54 modelFile = argv[i+1];
56 }
else if (strcmp(argv[i],
"-r")==0) {
57 redo_geom=redo_training=redo_lighting=
true;
58 }
else if (strcmp(argv[i],
"-g")==0) {
59 redo_geom=redo_lighting=
true;
60 }
else if (strcmp(argv[i],
"-l")==0) {
62 }
else if (strcmp(argv[i],
"-t")==0) {
64 }
else if (argv[i][0]==
'-') {
71 if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
72 capture = cvCaptureFromCAM( captureSrc[0]-
'0');
74 capture = cvCaptureFromAVI( captureSrc );
78 cerr <<
"Could not initialize capturing from " << captureSrc <<
" ...\n";
86 cout <<
"model.buildCached() failed.\n";
90 cout <<
"Model build. Starting geometric calibration.\n";
93 cerr <<
"Geometric calibration failed.\n";
97 cout <<
"Geometric calibration OK. Calibrating light...\n";
109 const char *win =
"BazAR";
113 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
117 IplImage* frame = cvQueryFrame(capture);
118 calib.
AddCamera(frame->width, frame->height);
119 IplImage* display=cvCloneImage(frame);
127 frame = cvQueryFrame( capture );
132 if (frame->nChannels >1) {
134 gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
135 cvCvtColor(frame, gray, CV_RGB2GRAY);
144 cout << nbHomography <<
" homographies.\n";
145 if (nbHomography >=70) {
168 cvShowImage(win, display);
171 if (k==
'q' || k== 27)
175 cvReleaseImage(&display);
176 if (frame->nChannels > 1)
177 cvReleaseImage(&gray);
185 int nbImages,
bool cache)
190 const char *win =
"BazAR";
194 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
195 cvNamedWindow(
"LightMap", CV_WINDOW_AUTOSIZE);
198 IplImage* display=cvCloneImage(cvQueryFrame(capture));
202 IplImage *lightmap = cvCreateImage(cvGetSize(model.
map.
map.
getIm()), IPL_DEPTH_8U,
207 frame = cvQueryFrame( capture );
216 if (frame->nChannels >1) {
218 gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
219 cvCvtColor(frame, gray, CV_RGB2GRAY);
235 for (
int j=0;j<3;j++) normal[j] = cvGet2D(mat, j, 2).val[0];
245 if (!model.
map.
isReady() && nbHomography >= nbImages) {
250 cout <<
"Gain: " << gain[0] <<
", " << gain[1] <<
", " << gain[2] << endl;
251 cout <<
"Bias: " << bias[0] <<
", " << bias[1] <<
", " << bias[2] << endl;
259 cvSetImageCOI(map, 2);
260 cvMinMaxLoc(map, &min, &max);
261 cvSetImageCOI(map, 0);
262 assert(map->nChannels == lightmap->nChannels);
263 cvConvertScale(map, lightmap, 128, 0);
264 cvShowImage(
"LightMap", lightmap);
267 cvCopy(frame,display);
272 cvShowImage(win, display);
275 if (k==
'q' || k== 27)
279 cvReleaseImage(&lightmap);
280 cvReleaseImage(&display);
281 if (frame->nChannels > 1)
282 cvReleaseImage(&gray);
301 3, CV_RGB(0,255,0), -1, 8,0);
309 cvCopy(frame, display);
319 CvMat ptsMat, projMat;
320 cvInitMatHeader(&ptsMat, 4, 4, CV_64FC1, pts);
321 cvInitMatHeader(&projMat, 3, 4, CV_64FC1, proj);
322 for (
int i=0; i<4; i++) {
323 pts[0][i] = model.
corners[i].x;
324 pts[1][i] = model.
corners[i].y;
328 cvMatMul(m, &ptsMat, &projMat);
332 for (
int i=0;i<4; i++) {
333 projPts[i].x = cvRound(proj[0][i]/proj[2][i]);
334 projPts[i].y = cvRound(proj[1][i]/proj[2][i]);
339 for (
int j=0;j<3;j++)
340 normal[j] = cvGet2D(o2w, j, 2).val[0];
345 CvScalar color = cvGet2D(model.
image, model.
image->height/2, model.
image->width/2);
346 CvScalar irradiance = model.
map.
readMap(normal);
354 for (
int i=0; i<3; i++) {
355 color.val[i] = 255.0*(g[i]*(color.val[i]/255.0)*irradiance.val[i] + b[i]);
359 cvFillConvexPoly(display, projPts, 4, color);
364 static std::vector<CamCalibration::s_struct_points> pts;
383 static std::vector<CamCalibration::s_struct_points> pts;