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 06:01:15 -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 :)Tue, 16 May 2017 05:50:38 -0500http://answers.opencv.org/question/148781/opengl-camera-to-opencv-projection-matrix/Comment by LBerger for <p>Hi!</p>
<p>I am trying to retrieve an OpenGL camera's parameters and use them for image processing.</p>
<p>I have my 4x4 Modelview from which I extract the camera's position and orientation as such:</p>
<pre><code>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
</code></pre>
<p>I retrieve the focal length and principal point from the Projection matrix as follow:</p>
<pre><code>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]);
</code></pre>
<p>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?</p>
<p>Thanks in advance :)</p>
http://answers.opencv.org/question/148781/opengl-camera-to-opencv-projection-matrix/?comment=148784#post-id-148784May be this [post](http://answers.opencv.org/question/23089/opencv-opengl-proper-camera-pose-using-solvepnp/) can help you and this [link](http://schabby.de/view-matrix/) too. You can use Viz too.Tue, 16 May 2017 06:01:15 -0500http://answers.opencv.org/question/148781/opengl-camera-to-opencv-projection-matrix/?comment=148784#post-id-148784