OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 16 May 2017 05:50:38 -0500OpenGL Camera to OpenCV Projection matrixhttp://answers.opencv.org/question/148781/opengl-camera-to-opencv-projection-matrix/ Hi!
I am trying to retrieve an OpenGL camera's parameters and use them for image processing.
I have my 4x4 Modelview from which I extract the camera's position and orientation as such:
Matrix3 R = glModelview.to3x3()
R.rotate(1, 0, 0, M_PI) // flip z axis
Vector3 camera_pos(glModelview[0][3], glModelview[1][3], glModelview[2][3]); // world position in camera's coordinates
I retrieve the focal length and principal point from the Projection matrix as follow:
glP = glProjectionMatrix;
double w = d_imageSize.x();
double h = d_imageSize.y();
double fx = 0.5 * w * glP[0][0];
double fy = 0.5 * h * (1.0 + glP[1][1]);
double cx = 0.5 * w * (1.0 - glP[0][3]);
double cy = 0.5 * h * (1.0 + glP[1][3]);
I now have my intrinsic and extrinsic parameters, and just compose the projection matrix.
Though it seems that I am missing something, as depending on the size of my OpenGL window (viewport) I get different results.
How could I integrate the viewport in my projection matrix?
Thanks in advance :)lagarkaneTue, 16 May 2017 05:50:38 -0500http://answers.opencv.org/question/148781/