20 #ifdef HAVE_APPLE_OPENGL_FRAMEWORK
21 #include <GLUT/glut.h>
45 GLfloat h = (GLfloat) height / (GLfloat) width;
47 glViewport(0, 0, (GLint) width, (GLint) height);
52 static void usage(
const char *s) {
53 cerr <<
"usage:\n" << s
54 <<
"[-m <model image>] [-r]\n"
55 " -m specifies model image\n"
56 " -r do not load any data\n"
57 " -t train a new classifier\n"
58 " -g recompute geometric calibration\n"
59 " -l rebuild irradiance map from scratch\n";
71 static bool init(
int argc,
char** argv )
74 bool redo_training=
false;
75 bool redo_lighting=
false;
79 for (
int i=1; i<argc; i++) {
80 if (strcmp(argv[i],
"-m") ==0) {
81 if (i==argc-1)
usage(argv[0]);
82 modelFile = argv[i+1];
84 }
else if (strcmp(argv[i],
"-r")==0) {
85 redo_geom=redo_training=redo_lighting=
true;
86 }
else if (strcmp(argv[i],
"-g")==0) {
87 redo_geom=redo_lighting=
true;
88 }
else if (strcmp(argv[i],
"-l")==0) {
90 }
else if (strcmp(argv[i],
"-t")==0) {
92 }
else if (argv[i][0]==
'-') {
101 if( multi->
init(!redo_training) ==0 )
103 cerr <<
"Initialization error.\n";
117 static void keyboard(
unsigned char c,
int x,
int y)
121 case '+' :
if (current_cam < multi->cams.size()-1)
128 case 'q': exit(0);
break;
131 case 'f': glutFullScreen();
break;
137 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
140 int main(
int argc,
char *argv[])
143 glutInit(&argc, argv);
144 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
146 glutCreateWindow(
"Multi-Cam Teapot augmentation");
149 if (!
init(argc,argv))
return -1;
151 cvDestroyAllWindows();
161 if (!tex || !tex->
getIm())
return false;
163 IplImage *im = tex->
getIm();
165 int h = im->height-1;
167 glMatrixMode(GL_PROJECTION);
169 glMatrixMode(GL_MODELVIEW);
173 glDisable(GL_DEPTH_TEST);
180 glTexCoord2f(tex->
u(0), tex->
v(0));
183 glTexCoord2f(tex->
u(w), tex->
v(0));
186 glTexCoord2f(tex->
u(w), tex->
v(h));
189 glTexCoord2f(tex->
u(0), tex->
v(h));
207 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
209 glDisable(GL_LIGHTING);
218 glMatrixMode(GL_PROJECTION);
220 glOrtho(0, im->width-1, im->height-1, 0, -1, 1);
222 glMatrixMode(GL_MODELVIEW);
226 glDisable(GL_LIGHTING);
227 glDisable(GL_DEPTH_TEST);
258 cout <<
"failed to load camera calibration.\n";
280 for (
int i=0; i<multi->
cams.size(); ++i) {
281 if (multi->
cams[i]->detect()) nbdet++;
284 if(!frameTexture) frameTexture =
new IplTexture;
288 for (
int i=0; i<multi->
cams.size(); ++i) {
289 if (multi->
cams[i]->detector.object_is_detected) {
301 (multi->
cams.size() > 1 ? 1:2),
302 (multi->
cams.size() > 1 ? 0:3),
337 for (
int i=0; i<multi->
cams.size(); ++i) {
353 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
355 glDisable(GL_LIGHTING);
368 Mat3x4 moveObject, rot, obj2World, movedRT_;
369 moveObject.
setTranslate(im->width/2,im->height/2,-120*3/4);
372 CvMat cvMoveObject = cvMat(3,4,CV_64FC1, moveObject.
m);
373 CvMat movedRT=cvMat(3,4,CV_64FC1,movedRT_.
m);
376 for(
int i = 0; i < 3; i++ )
377 for(
int j = 0; j < 4; j++ ) {
378 a_proj[i][j] =
cvmGet( proj, i, j );
379 obj2World.
m[i][j] =
cvmGet(world, i, j);
394 glEnable(GL_DEPTH_TEST);
395 glDisable(GL_LIGHTING);
398 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
400 glDisable(GL_CULL_FACE);
430 for (
int i=0; i<3; i++) {
431 color.val[i] = (g[i]*(color.val[i]/255.0)*irradiance.val[i] + b[i]);
433 glColor3d(color.val[2], color.val[1], color.val[0]);
456 glDisable(GL_LIGHTING);
463 GLfloat light_diffuse[] = {1.0, 1, 1, 1.0};
464 GLfloat light_position[] = {500, 400.0, 500.0, 1};
467 w2obj.
transform(light_position, light_position);
468 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
469 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
471 glEnable(GL_LIGHTING);
474 cvReleaseMat(&world);
479 glColor3d(c.val[2], c.val[1], c.val[0]);
481 glEnable(GL_CULL_FACE);
484 glutSolidSphere(120, 16, 16);
486 glCullFace(GL_FRONT);
492 glRotatef(-270, 1.0, 0.0, 0.0);
493 glutSolidTeapot(120);
496 glDisable(GL_CULL_FACE);
504 glutSolidSphere(120, 16, 16);
510 glDisable(GL_LIGHTING);
514 glDisable(GL_DEPTH_TEST);
515 glDisable(GL_CULL_FACE);
517 glMatrixMode(GL_PROJECTION);
519 glMatrixMode(GL_MODELVIEW);
534 glEnable(GL_DEPTH_TEST);
556 for (
int i=0; i<multi->
cams.size(); ++i) {
557 if (multi->
cams[i]->detect()) nbdet++;
560 if(!frameTexture) frameTexture =
new IplTexture;
566 for (
int i=0; i<multi->
cams.size(); ++i) {
567 if (multi->
cams[i]->detector.object_is_detected) {
580 for (
int j=0;j<3;j++) normal[j] = cvGet2D(mat, j, 2).val[0];
586 for (
int i=0; i<multi->
cams.size();++i) {
588 if (multi->
cams[i]->detector.object_is_detected) {