OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 13 Mar 2017 08:37:05 -0500How to derive camera position from solvePnP? Not a repeated question.http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/ Hi, can someone help me?
From the post, "camera-position-in-world-coordinate-from-cvsolvepnp"@ stackoverflow, it gave the answer of how to derive camera position in world coordinate from cv::solvePnP. However, I still can not get a correct solution from that page.
My experiment is facing a wall with a poster and move straight toward the poster step by step. Unfortunately, the trace of the sequence of camera's coordinates are not a straight line.
From my understanding, solvePnP() will return the rotation and translation of the object in camera coordinate system. Notice that, they are object's rotation and translation in camera coordinate system. So, the whole question become: **Give a poster's rotation and translation in camera coordinate system, how can we derive camera's position in poster's original world space**?
From my understand go 3D computer graphics, I am skeptical about the solution from above post. Can someone help me to solve the puzzle. Thanks,Mon, 13 Mar 2017 04:40:19 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/Comment by yorkhuang for <p>Hi, can someone help me?
From the post, "camera-position-in-world-coordinate-from-cvsolvepnp"@ stackoverflow, it gave the answer of how to derive camera position in world coordinate from cv::solvePnP. However, I still can not get a correct solution from that page.
My experiment is facing a wall with a poster and move straight toward the poster step by step. Unfortunately, the trace of the sequence of camera's coordinates are not a straight line.
From my understanding, solvePnP() will return the rotation and translation of the object in camera coordinate system. Notice that, they are object's rotation and translation in camera coordinate system. So, the whole question become: <strong>Give a poster's rotation and translation in camera coordinate system, how can we derive camera's position in poster's original world space</strong>?
From my understand go 3D computer graphics, I am skeptical about the solution from above post. Can someone help me to solve the puzzle. Thanks,</p>
http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133830#post-id-133830After further search the Internet, from the post, "How to find the position of camera given the known world coordinate of objects?"@http://cs.stackexchange.com/, it seem that we need to further consider camera's intrinsic parameter when we want to derive camera's world position from the return value of solvePnP. Am I correct? Pleas help. Thank you,Mon, 13 Mar 2017 05:14:41 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133830#post-id-133830Comment by Eduardo for <p>Hi, can someone help me?
From the post, "camera-position-in-world-coordinate-from-cvsolvepnp"@ stackoverflow, it gave the answer of how to derive camera position in world coordinate from cv::solvePnP. However, I still can not get a correct solution from that page.
My experiment is facing a wall with a poster and move straight toward the poster step by step. Unfortunately, the trace of the sequence of camera's coordinates are not a straight line.
From my understanding, solvePnP() will return the rotation and translation of the object in camera coordinate system. Notice that, they are object's rotation and translation in camera coordinate system. So, the whole question become: <strong>Give a poster's rotation and translation in camera coordinate system, how can we derive camera's position in poster's original world space</strong>?
From my understand go 3D computer graphics, I am skeptical about the solution from above post. Can someone help me to solve the puzzle. Thanks,</p>
http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133863#post-id-133863@yorkhuang The [link](https://stackoverflow.com/questions/18637494/camera-position-in-world-coordinate-from-cvsolvepnp) you mention give the exact same answer than me (I didn't bother to consult the link).Mon, 13 Mar 2017 08:37:05 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133863#post-id-133863Answer by Eduardo for <p>Hi, can someone help me?
From the post, "camera-position-in-world-coordinate-from-cvsolvepnp"@ stackoverflow, it gave the answer of how to derive camera position in world coordinate from cv::solvePnP. However, I still can not get a correct solution from that page.
My experiment is facing a wall with a poster and move straight toward the poster step by step. Unfortunately, the trace of the sequence of camera's coordinates are not a straight line.
From my understanding, solvePnP() will return the rotation and translation of the object in camera coordinate system. Notice that, they are object's rotation and translation in camera coordinate system. So, the whole question become: <strong>Give a poster's rotation and translation in camera coordinate system, how can we derive camera's position in poster's original world space</strong>?
From my understand go 3D computer graphics, I am skeptical about the solution from above post. Can someone help me to solve the puzzle. Thanks,</p>
http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?answer=133829#post-id-133829 What you are looking for is called Homogeneous transformation matrix.
To get the 3D coordinate of the camera in the poster frame, assuming a known camera pose, you just have to compute what is called the inverse of the homogenous matrix (see this [course, page 72](http://www-lar.deis.unibo.it/people/cmelchiorri/Files_Robotica/FIR_03_Rbody.pdf), Ridig Body Motion – Homogeneous Transformations by Claudio Melchiorri).
**I strongly recommend to read a course about homogeneous transformation** (the one linked should be good).
----------
I recall the equations in case the link is no more accessible.
![eq1](/upfiles/14894012446497313.png)
![eq2](/upfiles/14894012799938909.png)
The superscript `t` in `cRp^t` simply means the transpose of matrix.
----------
Note:
[`solvePnP()`](http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d) returning a rotation vector and a translation vector, you will have to use [`Rodrigues()`](http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac) to compute the rotation matrix from the rotation vector.Mon, 13 Mar 2017 05:13:43 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?answer=133829#post-id-133829Comment by yorkhuang for <p>What you are looking for is called Homogeneous transformation matrix.</p>
<p>To get the 3D coordinate of the camera in the poster frame, assuming a known camera pose, you just have to compute what is called the inverse of the homogenous matrix (see this <a href="http://www-lar.deis.unibo.it/people/cmelchiorri/Files_Robotica/FIR_03_Rbody.pdf">course, page 72</a>, Ridig Body Motion – Homogeneous Transformations by Claudio Melchiorri).</p>
<p><strong>I strongly recommend to read a course about homogeneous transformation</strong> (the one linked should be good).</p>
<hr/>
<p>I recall the equations in case the link is no more accessible.</p>
<p><img alt="eq1" src="/upfiles/14894012446497313.png"/></p>
<p><img alt="eq2" src="/upfiles/14894012799938909.png"/></p>
<p>The superscript <code>t</code> in <code>cRp^t</code> simply means the transpose of matrix.</p>
<hr/>
<p>Note:</p>
<p><a href="http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d"><code>solvePnP()</code></a> returning a rotation vector and a translation vector, you will have to use <a href="http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac"><code>Rodrigues()</code></a> to compute the rotation matrix from the rotation vector.</p>
http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133851#post-id-133851I had read the course materia](http://www-lar.deis.unibo.it/people/cmelchiorri/Files_Robotica/FIR_03_Rbody.pdf)l provided by Eduardo and still not solve my doubt about how to derive the camera position from solvePnP(). My main peradventure is the rotation vector and a translation vector from solvePnP() is the object in the camera coordinate system. Are we really can use these two vectors to compute the camera pose from equations above?Mon, 13 Mar 2017 07:50:45 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133851#post-id-133851Comment by yorkhuang for <p>What you are looking for is called Homogeneous transformation matrix.</p>
<p>To get the 3D coordinate of the camera in the poster frame, assuming a known camera pose, you just have to compute what is called the inverse of the homogenous matrix (see this <a href="http://www-lar.deis.unibo.it/people/cmelchiorri/Files_Robotica/FIR_03_Rbody.pdf">course, page 72</a>, Ridig Body Motion – Homogeneous Transformations by Claudio Melchiorri).</p>
<p><strong>I strongly recommend to read a course about homogeneous transformation</strong> (the one linked should be good).</p>
<hr/>
<p>I recall the equations in case the link is no more accessible.</p>
<p><img alt="eq1" src="/upfiles/14894012446497313.png"/></p>
<p><img alt="eq2" src="/upfiles/14894012799938909.png"/></p>
<p>The superscript <code>t</code> in <code>cRp^t</code> simply means the transpose of matrix.</p>
<hr/>
<p>Note:</p>
<p><a href="http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d"><code>solvePnP()</code></a> returning a rotation vector and a translation vector, you will have to use <a href="http://docs.opencv.org/3.2.0/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac"><code>Rodrigues()</code></a> to compute the rotation matrix from the rotation vector.</p>
http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133834#post-id-133834Thank you for Eduardo's answer. However, according to your equation, it is exactly the same as the post, "camera-position-in-world-coordinate-from-cvsolvepnp"@ stackoverflow. I tried that already and had no luck at all. Am I misunderstand your answer?
Thanks again for your kindness help!Mon, 13 Mar 2017 05:40:16 -0500http://answers.opencv.org/question/133820/how-to-derive-camera-position-from-solvepnp-not-a-repeated-question/?comment=133834#post-id-133834