Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

OpenCV + OpenGL: How to use SolvePnP Rotation and translation vector in OpenGL

$
0
0
I'm working on an AR program. please heip me dealing's almost done. I found marker and rvec,tvec by SolvePnP. I can not draw object in OpenGL. I am beginer OpenGL,OpenCV. I want to render 3D cube over that marker using OpenGL. use support opengl mode by build opencv. int main(int argc, char* argv[]) { .... namedWindow(winname, CV_WINDOW_OPENGL); setOpenGlDrawCallback(winname.c_str(), on_opengl); ..... find marker According to "http://answers.opencv.org/question/23089/opencv-opengl-proper-camera-pose-using-solvepnp/" I'm doing it like this: Mat rotation(4, 4, CV_64F); Mat viewMatrix = cv::Mat::zeros(4, 4, CV_64FC1); cv::Rodrigues(rvec, rotation); for (unsigned int row = 0; row<3; ++row) { for (unsigned int col = 0; col<3; ++col) { viewMatrix.at(row, col) = rotation.at(row, col); } viewMatrix.at(row, 3) = tvec.at(row, 0); } viewMatrix.at(3, 3) = 1.0f; cv::Mat glViewMatrix = cv::Mat::zeros(4, 4, CV_64F); cv::transpose(viewMatrix, glViewMatrix); glViewMatrix2 = glViewMatrix.clone(); opengl callback void on_opengl(void* param) { glClear(GL_COLOR_BUFFER_BIT); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd(&glViewMatrix2.at(0, 0)); //glTranslated(glViewMatrix2.at(0, 3), -glViewMatrix2.at(1, 3),0); //glTranslated(glViewMatrix2.at(3, 0), -glViewMatrix2.at(3, 1), -glViewMatrix2.at(3, 2)); glTranslated(0.0, 0.0, 0.0); static const int coords[6][4][3] = { { { +1, -1, -1 },{ -1, -1, -1 },{ -1, +1, -1 },{ +1, +1, -1 } }, { { +1, +1, -1 },{ -1, +1, -1 },{ -1, +1, +1 },{ +1, +1, +1 } }, { { +1, -1, +1 },{ +1, -1, -1 },{ +1, +1, -1 },{ +1, +1, +1 } }, { { -1, -1, -1 },{ -1, -1, +1 },{ -1, +1, +1 },{ -1, +1, -1 } }, { { +1, -1, +1 },{ -1, -1, +1 },{ -1, -1, -1 },{ +1, -1, -1 } }, { { -1, -1, +1 },{ +1, -1, +1 },{ +1, +1, +1 },{ -1, +1, +1 } } }; for (int i = 0; i < 6; ++i) { glColor3ub(i * 20, 100 + i * 10, i * 42); glBegin(GL_QUADS); for (int j = 0; j < 4; ++j) { glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]); } glEnd(); } } i cannot find cube. if I delete "glLoadMatrixd(&glViewMatrix2.at(0, 0));" this line. I can find cube on center. Q2-How to use glut.where can I do"glutInit(&argc2, argv2);"

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>