20 cerr <<
"usage:\n" << s
21 <<
"[-m <model image>] [-r]\n"
22 " -m specifies model image\n"
23 " -r do not load any data\n"
24 " -t train a new classifier\n"
25 " -g recompute geometric calibration\n"
26 " -l rebuild irradiance map from scratch\n";
30 int main(
int argc,
char** argv )
33 bool redo_training=
false;
34 bool redo_lighting=
false;
38 for (
int i=1; i<argc; i++) {
39 if (strcmp(argv[i],
"-m") ==0) {
40 if (i==argc-1)
usage(argv[0]);
41 modelFile = argv[i+1];
43 }
else if (strcmp(argv[i],
"-r")==0) {
44 redo_geom=redo_training=redo_lighting=
true;
45 }
else if (strcmp(argv[i],
"-g")==0) {
46 redo_geom=redo_lighting=
true;
47 }
else if (strcmp(argv[i],
"-l")==0) {
49 }
else if (strcmp(argv[i],
"-t")==0) {
51 }
else if (argv[i][0]==
'-') {
58 if( multi.
init(!redo_training) ==0 )
60 cerr <<
"Initialization error.\n";
64 cout <<
"Starting geometric calibration.\n";
67 cerr <<
"Geometric calibration failed.\n";
71 cout <<
"Geometric calibration OK. Calibrating light...\n";
86 const char *win =
"BazAR";
88 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
93 for (
int i=0; i<multi.
cams.size(); ++i) {
111 for (
int i=0; i<multi.
cams.size(); ++i) {
112 if (multi.
cams[i]->detect()) nbdet++;
116 for (
int i=0; i<multi.
cams.size(); ++i) {
117 if (multi.
cams[i]->detector.object_is_detected) {
126 if (nbHomography >=200) {
129 (multi.
cams.size() > 1 ? 1:2),
147 if (display==0) display = cvCreateImage(cvGetSize(multi.
cams[dispCam]->frame), IPL_DEPTH_8U, 3);
149 cvShowImage(win, display);
154 case 27: end=
true;
break;
155 case 'n':
if(dispCam < multi.
cams.size()-1) {
156 cvReleaseImage(&display);
159 cout <<
"Current cam: " << dispCam << endl;
161 case 'p':
if(dispCam > 0) {
162 cvReleaseImage(&display);
165 cout <<
"Current cam: " << dispCam << endl;
168 default: cout << (char)k <<
": What ?\n";
172 if (display) cvReleaseImage(&display);
185 const char *win =
"BazAR";
187 cvNamedWindow(win, CV_WINDOW_AUTOSIZE);
203 for (
int i=0; i<multi.
cams.size(); ++i) {
204 if (multi.
cams[i]->detect()) nbdet++;
210 for (
int i=0; i<multi.
cams.size(); ++i) {
211 if (multi.
cams[i]->detector.object_is_detected) {
220 if (display==0) display = cvCreateImage(cvGetSize(multi.
cams[dispCam]->frame), IPL_DEPTH_8U, 3);
226 for (
int j=0;j<3;j++) normal[j] = cvGet2D(mat, j, 2).val[0];
230 for (
int i=0; i<multi.
cams.size();++i) {
231 if (multi.
cams[i]->detector.object_is_detected) {
236 if (!model.
map.
isReady() && nbLightMeasures > 40) {
244 cvCopy( multi.
cams[dispCam]->frame, display);
246 cvShowImage(win, display);
251 case 27: end=
true;
break;
252 case 'n':
if(dispCam < multi.
cams.size()-1) {
253 cvReleaseImage(&display);
256 cout <<
"Current cam: " << dispCam << endl;
258 case 'p':
if(dispCam > 0) {
259 cvReleaseImage(&display);
262 cout <<
"Current cam: " << dispCam << endl;
265 default: cout << (char)k <<
": What ?\n";
269 if (display) cvReleaseImage(&display);
293 3, CV_RGB(0,255,0), -1, 8,0);
301 cvCopy(frame, display);
308 CvMat ptsMat, projMat;
309 cvInitMatHeader(&ptsMat, 4, 4, CV_64FC1, pts);
310 cvInitMatHeader(&projMat, 3, 4, CV_64FC1, proj);
311 for (
int i=0; i<4; i++) {
312 pts[0][i] = model.
corners[i].x;
313 pts[1][i] = model.
corners[i].y;
317 cvMatMul(m, &ptsMat, &projMat);
321 for (
int i=0;i<4; i++) {
322 projPts[i].x = cvRound(proj[0][i]/proj[2][i]);
323 projPts[i].y = cvRound(proj[1][i]/proj[2][i]);
326 CvScalar color = cvScalar(128,128,128,128);
331 for (
int j=0;j<3;j++)
332 normal[j] = cvGet2D(o2w, j, 2).val[0];
337 color = cvGet2D(model.
image, model.
image->height/2, model.
image->width/2);
338 CvScalar irradiance = model.
map.
readMap(normal);
346 for (
int i=0; i<3; i++) {
347 color.val[i] = 255.0*(g[i]*(color.val[i]/255.0)*irradiance.val[i] + b[i]);
352 cvFillConvexPoly(display, projPts, 4, color);