void vDrawScene() { if (TheResizedImage.rows==0) //prevent from going on until the image is initialized return; ///clear glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ///draw image in the buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, TheGlWindowSize.width, 0, TheGlWindowSize.height, -1.0, 1.0); glViewport(0, 0, TheGlWindowSize.width , TheGlWindowSize.height); glDisable(GL_TEXTURE_2D); glPixelZoom( 1, -1); glRasterPos3f( 0, TheGlWindowSize.height - 0.5, -1.0 ); glDrawPixels ( TheGlWindowSize.width , TheGlWindowSize.height , GL_RGB , GL_UNSIGNED_BYTE , TheResizedImage.ptr(0) ); ///Set the appropriate projection matrix so that rendering is done in a enrvironment //like the real camera (without distorsion) glMatrixMode(GL_PROJECTION); double proj_matrix[16]; TheCameraParams.glGetProjectionMatrix(TheInputImage.size(),TheGlWindowSize,proj_matrix,0.05,10); glLoadIdentity(); glLoadMatrixd(proj_matrix); glLineWidth(2); //now, for each marker, double modelview_matrix[16]; /* for (unsigned int m=0;m<TheMarkers.size();m++) { TheMarkers[m].glGetModelViewMatrix(modelview_matrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(modelview_matrix); // axis(TheMarkerSize); glColor3f(1,0.4,0.4); glTranslatef(0, TheMarkerSize/2,0); glPushMatrix(); glutWireCube( TheMarkerSize ); glPopMatrix(); }*/ //If the board is detected with enough probability if (TheBoardDetected.second>0.3) { TheBoardDetected.first.glGetModelViewMatrix(modelview_matrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(modelview_matrix); glColor3f(0,1,0); glTranslatef(0, TheMarkerSize/2,0); glPushMatrix(); glutWireCube( TheMarkerSize ); axis(TheMarkerSize); glPopMatrix(); } glutSwapBuffers(); }
/*! * */ static void vDrawScene() { if (resImg.rows==0) //prevent from going on until the image is initialized return; ///clear glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ///draw image in the buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, glSize.width, 0, glSize.height, -1.0, 1.0); glViewport(0, 0, glSize.width , glSize.height); glDisable(GL_TEXTURE_2D); glPixelZoom( 1, -1); glRasterPos3f( 0, glSize.height - 0.5, -1.0 ); glDrawPixels (glSize.width , glSize.height , GL_BGR_EXT , GL_UNSIGNED_BYTE , resImg.ptr(0) ); ///Set the appropriate projection matrix so that rendering is done in a enrvironment //like the real camera (without distorsion) glMatrixMode(GL_PROJECTION); double proj_matrix[16]; camParams.glGetProjectionMatrix(inImg.size(),glSize,proj_matrix,0.05,10); glLoadIdentity(); glLoadMatrixd(proj_matrix); //now, for each marker, double modelview_matrix[16]; for (unsigned int m=0; m<markers.size(); m++) { markers[m].glGetModelViewMatrix(modelview_matrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(modelview_matrix); axis(msiz->dval[0]); glColor3f(1,0.4,0.4); glTranslatef(0, msiz->dval[0]/2,0); glPushMatrix(); glutWireCube( msiz->dval[0] ); glPopMatrix(); } glutSwapBuffers(); }
void MarkerDetector::glGetProjectionMatrix ( CameraParameters & CamMatrix,cv::Size orgImgSize, cv::Size size,double proj_matrix[16],double gnear,double gfar,bool invert ) throw ( cv::Exception ) { cerr<<"MarkerDetector::glGetProjectionMatrix . This a deprecated function. Use CameraParameters::glGetProjectionMatrix instead. "<<__FILE__<<" "<<__LINE__<<endl; CamMatrix.glGetProjectionMatrix ( orgImgSize,size,proj_matrix,gnear,gfar,invert ); }
void vDrawScene() { if (TheResizedImage.rows==0)// prevent from going on until the image is initialized return; ///clear glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //glColor3f(1.0f,0.0f,0.0f); // draw image in the buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, TheGlWindowSize.width, 0, TheGlWindowSize.height, -1.0, 1.0); glViewport(0, 0, TheGlWindowSize.width , TheGlWindowSize.height); glDisable(GL_TEXTURE_2D); glPixelZoom( 1, -1); glRasterPos3f( 0, TheGlWindowSize.height - 0.5, -1.0 ); glDrawPixels ( TheGlWindowSize.width , TheGlWindowSize.height , GL_RGB , GL_UNSIGNED_BYTE , TheResizedImage.ptr(0) ); ///Set the appropriate projection matrix so that rendering is done in a enrvironment //like the real camera (without distorsion) glMatrixMode(GL_PROJECTION); double proj_matrix[16]; TheCameraParams.glGetProjectionMatrix(TheInputImage.size(),TheGlWindowSize,proj_matrix,0.05,10); glLoadIdentity(); glLoadMatrixd(proj_matrix); //now, for each marker, double modelview_matrix[16]; glMatrixMode(GL_MODELVIEW); //Deepak Comment here glPushMatrix(); vector<cv::Point2f> centers; for (unsigned int m=0;m<TheMarkers.size();m++) { centers.push_back(TheMarkers[m].getCenter()); // TheMarkers[m].glGetModelViewMatrix(modelview_matrix); // glLoadIdentity(); // glLoadMatrixd(modelview_matrix); // axis(TheMarkerSize); // glColor3f(1,0.4,0.4); // glTranslatef(0, TheMarkerSize/2,0); // glPushMatrix(); // glutWireCube( TheMarkerSize ); // glPopMatrix(); } char textString[100] = "Free Mode"; char unitString[100] = "Metric Units"; if ( mode == Free){ freeMode(centers); int a = sprintf(textString,"%s","Free Mode"); } else if (mode == Triangle){ triangleMode(centers); int a = sprintf(textString,"%s","Triangle Exploration Mode"); } else if (mode == Grid){ int a = sprintf(textString,"%s","Grid Mode"); gridMode(centers); } else if (mode == Line){ int a = sprintf(textString,"%s","Line Mode"); lineMode(centers); } else if (mode == Line2){ int a = sprintf(textString,"%s","Line Mode2"); lineMode2(centers); } int m =sprintf(unitString,"%s",imperialUnitFlag?"Imperial Units":"Metric Units"); if (centers.size() > 0){ cv::Mat t0 = TheMarkers[0].Tvec; float xTranslate = -0.1f; float yTranslate = -0.1f; glPushMatrix(); glLoadIdentity(); glColor4f(1.0f,0.0f,0.0f,0.5f); glTranslatef(t0.at<float>(0,0) + xTranslate,t0.at<float>(1,0)+yTranslate,-t0.at<float>(2,0)); glRasterPos3f( 0.0f,0.0f,0.0f ); char buffer[100]; int n = sprintf(buffer,"%s \n%s",textString,unitString); drawString(buffer); glPopMatrix(); } glutSwapBuffers(); }