|||
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//要画在x,y,-z平面上,因为图像沿着Z轴推远了,能看到的物体z值是负数
glRotatef(180, 1.0, 0.0, 0.0 );
//M矩阵是以连乘的形式使用,M是列优先矩阵象Matlab里一样
glMultMatrixf(M);//画坐标轴
DrawAxis(0.0f,0.0f,0.0f,base_length);
//因为焦距是在320×240图像上得到的
fov = 2 * atan(240/2/fol)*180/3.14159265;gluPerspective(fov, 4.0/3.0, znear, 100.0f);
glDisable(GL_DEPTH_TEST); //这句很重要glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glOrtho(0,wid,hei,0,-1,1);//glOrtho(0,wid,0,hei,-1,1);用那个取决于输入图像是否颠倒glMatrixMode(GL_MODELVIEW);glPushMatrix();glLoadIdentity();glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texName);
gluBuild2DMipmaps( GL_TEXTURE_2D,GL_RGB, wid,hei,GL_BGR_EXT, GL_UNSIGNED_BYTE,camInput->imageData);glBegin(GL_QUADS); //贴图
glTexCoord2f(0.0, 0.0); glVertex3f(0,0,0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(0, hei, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(wid,hei,0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(wid,0,0.0);
glEnd();glMatrixMode(GL_PROJECTION); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glPopMatrix();
void idle()
{
if(IsVideo) //得到当前帧
camInput = cvQueryFrame(capture);
cvShowImage("OpenCV Webcam Input", camInput);
glutPostRedisplay(); //强制调用显示回调函数 display()
}也就是说主程序应该是下面这种形式的:InitGL();
InitCV();glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);glutIdleFunc(idle);glutMainLoop(); //取代了OpenCV里的for(;;)
}
增强视觉应用的难点还是在于利用机器视觉分析场景结构和姿态的部分,简单地说就是如何跟踪那本书,和如何计算K,R和T等。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-8-18 02:11
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社