#include #include #include #include #include "main.h" #include #include "GL/glut.h" #include #include #include "tsai.h" int WIDTH, HEIGHT; bool calculouDistFocal = false; float distanciaFocal; float translacao[3], rotacao[9]; float mtsaiopengl_modelview[16], mtsaiopengl_projection[16]; IplImage* frame = 0; CvCapture* capture = 0; CvSize sizeChessboard = cvSize(8,6); CvPoint2D32f* corners; int corner_count; float *xw, *yw, *xf, *yf; void reshape( int w, int h ) { WIDTH = w; HEIGHT = h; display(); } void display(void) { int i,j; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, WIDTH, 0.0, HEIGHT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if(!cvGrabFrame(capture)) { free(corners); cvReleaseCapture(&capture); glutDestroyWindow(glutGetWindow()); free(xw); free(yw); free(xf); free(yf); exit( 0 ); } // calibração da camera int flag = calibrarCamera(); if (flag != 0) { // carrega matrizes de projecao e de transformacao glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glLoadMatrixf(mtsaiopengl_projection); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glLoadMatrixf(mtsaiopengl_modelview); // desenha os corners do tabuleiro glColor3f(1,0,0); glPointSize(5); glBegin(GL_POINTS); for(i=0; iimageData); // encontra os corners do tabuleiro int flag = cvFindChessboardCorners(img_aux,sizeChessboard,corners,&corner_count,CV_CALIB_CB_ADAPTIVE_THRESH); if (flag != 0) { int px = 0, py = 0; for(i=0; i 7) { py++; px = 0; } } if (!calculouDistFocal) { tsaiCalibration2D(corner_count,xw,yw,xf,yf,&distanciaFocal,translacao,rotacao); calculouDistFocal = true; } else tsaiCalibration2D_Tr(corner_count,xw,yw,xf,yf,distanciaFocal,translacao,rotacao); tsaiOGLModelViewMatrix(translacao,rotacao,mtsaiopengl_modelview); tsaiOGLProjectionMatrix(distanciaFocal, 10, 1000, WIDTH, HEIGHT, mtsaiopengl_projection); } cvReleaseImage(&img_aux); return flag; } void initVideo() { FILE *arquivo; char nome[100]; arquivo = fopen("inicio.txt","r"); fscanf(arquivo,"%s",&nome); fscanf(arquivo,"%d",&WIDTH); fscanf(arquivo,"%d",&HEIGHT); fclose(arquivo); capture = cvCaptureFromAVI(nome); //capture = cvCaptureFromCAM(1); corners = (CvPoint2D32f*)malloc((sizeChessboard.width*sizeChessboard.height) * sizeof(CvPoint2D32f)); xw = (float *)malloc(48*sizeof(float)); yw = (float *)malloc(48*sizeof(float)); xf = (float *)malloc(48*sizeof(float)); yf = (float *)malloc(48*sizeof(float)); } int main(int argc, char* argv[]) { initVideo(); glutInit(&argc,argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(WIDTH,HEIGHT); glutCreateWindow ("RA - Trabalho 2"); glutDisplayFunc ( display ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); //glutSpecialFunc (); glutIdleFunc ( display ); glutMainLoop ( ); return 0; }