OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 20 Mar 2018 07:48:20 -0500composeRT input/output questionhttp://answers.opencv.org/question/186217/composert-inputoutput-question/ I have two frame transformations, one from frame 0 to frame 1, and one from frame 1 to frame 2, and I would like to concatenate these into the transformation from frame 0 to frame 2. I'm computing the pose of a moving camera, and the first transformation (0-1) represent the previous pose of the camera (transformation from its initial pose) and the 1-2 transformation is the newest change of pose, represented by tvec and rvec gotten from solvePnPRansac.
However, as I cannot just try out different inputs in my code and see if the output seems correct, since my system currently consists of lots of noise, I would like to have the math check out before I implement it into my application. But while I try to use the formulas given in the documentation with different rvecs and tvecs, I can't get the outputs (rvec3/tvec3) I want. These are the formulas:
![image description](/upfiles/15204294873689042.png)
I've tried with the following rvecs/tvecs:
- rvec1: Rotation *from* frame 1 *to* frame 0
- tvec1: vector *from* the origin of frame 0 *to* the origin of frame 1, given in *frame 0 coordinates*
- rvec2: Rotation *from* frame 2 *to* frame 1
- tvec2: vector *from* the origin of frame 1 *to* the origin of frame 2, given in *frame 1 coordinates*
I want to end up with:
- rvec3: Rotation from frame 0 to frame 2 (or inversed, doesn't matter)
- tvec3: vector *from* frame 0 *to* frame 2 given in *frame 0 coordinates* (or negated)
However, with these vectors, I can't get the formula in the documentation to make sense. The rvec3-formula makes sense, and with rvec1/rvec2 I get rvec3=(rvec2*rvec1)⁻¹ to equal the rotation from frame 2 to frame 0. However, the computation of tvec3 doesn't add up:
The formula says tvec3 = rvec2 * tvec1 + tvec2, but rvec2 * tvec1 doesn't make sense with my vectors. I mean, it says to rotate a vector given in frame 0 coordinates from frame 2 to frame 1. A vector given in frame 0 coordinates need to be multiplied with a rotation matrix representing the rotation *from* frame 0 to some other frame, but this is not the case here. And it haven't made sense with any other vectors I've tried as well, for that matter.
Someone that could help me with these calculcations? Thanks!
Wed, 07 Mar 2018 07:38:10 -0600http://answers.opencv.org/question/186217/composert-inputoutput-question/Answer by Eduardo for <p>I have two frame transformations, one from frame 0 to frame 1, and one from frame 1 to frame 2, and I would like to concatenate these into the transformation from frame 0 to frame 2. I'm computing the pose of a moving camera, and the first transformation (0-1) represent the previous pose of the camera (transformation from its initial pose) and the 1-2 transformation is the newest change of pose, represented by tvec and rvec gotten from solvePnPRansac.</p>
<p>However, as I cannot just try out different inputs in my code and see if the output seems correct, since my system currently consists of lots of noise, I would like to have the math check out before I implement it into my application. But while I try to use the formulas given in the documentation with different rvecs and tvecs, I can't get the outputs (rvec3/tvec3) I want. These are the formulas:</p>
<p><img alt="image description" src="/upfiles/15204294873689042.png"></p>
<p>I've tried with the following rvecs/tvecs:</p>
<ul>
<li>rvec1: Rotation <em>from</em> frame 1 <em>to</em> frame 0</li>
<li>tvec1: vector <em>from</em> the origin of frame 0 <em>to</em> the origin of frame 1, given in <em>frame 0 coordinates</em></li>
<li>rvec2: Rotation <em>from</em> frame 2 <em>to</em> frame 1</li>
<li>tvec2: vector <em>from</em> the origin of frame 1 <em>to</em> the origin of frame 2, given in <em>frame 1 coordinates</em></li>
</ul>
<p>I want to end up with:</p>
<ul>
<li>rvec3: Rotation from frame 0 to frame 2 (or inversed, doesn't matter)</li>
<li>tvec3: vector <em>from</em> frame 0 <em>to</em> frame 2 given in <em>frame 0 coordinates</em> (or negated)</li>
</ul>
<p>However, with these vectors, I can't get the formula in the documentation to make sense. The rvec3-formula makes sense, and with rvec1/rvec2 I get rvec3=(rvec2*rvec1)⁻¹ to equal the rotation from frame 2 to frame 0. However, the computation of tvec3 doesn't add up:</p>
<p>The formula says tvec3 = rvec2 * tvec1 + tvec2, but rvec2 * tvec1 doesn't make sense with my vectors. I mean, it says to rotate a vector given in frame 0 coordinates from frame 2 to frame 1. A vector given in frame 0 coordinates need to be multiplied with a rotation matrix representing the rotation <em>from</em> frame 0 to some other frame, but this is not the case here. And it haven't made sense with any other vectors I've tried as well, for that matter.</p>
<p>Someone that could help me with these calculcations? Thanks!</p>
http://answers.opencv.org/question/186217/composert-inputoutput-question/?answer=186226#post-id-186226The formulas look correct for me. The corresponding equations are given below.
The transformation that allows converting a 3D point expressed in the frame 0 to the frame 1 is:
![Eq1-1](/upfiles/15204351195435918.png)
![Eq1-2](/upfiles/15204359059777849.png)
The transformation that allows converting a 3D point expressed in the frame 1 to the frame 2 is:
![Eq2](/upfiles/15204352216040811.png)
The transformation that allows converting a 3D point expressed in the frame 0 to the frame 2 is then:
![Eq3](/upfiles/1520435259800403.png)
![Eq4](/upfiles/15204364024066438.png)
Note that as `rvec` is a Rodriges rotation vector, `rodrigues(rvec)` gives the corresponding rotation matrix `R`.Wed, 07 Mar 2018 09:26:57 -0600http://answers.opencv.org/question/186217/composert-inputoutput-question/?answer=186226#post-id-186226Comment by bendikiv for <p>The formulas look correct for me. The corresponding equations are given below.</p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 1 is:
<img alt="Eq1-1" src="/upfiles/15204351195435918.png"></p>
<p><img alt="Eq1-2" src="/upfiles/15204359059777849.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 1 to the frame 2 is:
<img alt="Eq2" src="/upfiles/15204352216040811.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 2 is then:
<img alt="Eq3" src="/upfiles/1520435259800403.png">
<img alt="Eq4" src="/upfiles/15204364024066438.png"></p>
<p>Note that as <code>rvec</code> is a Rodriges rotation vector, <code>rodrigues(rvec)</code> gives the corresponding rotation matrix <code>R</code>.</p>
http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=187200#post-id-187200I see! Thanks!Tue, 20 Mar 2018 07:48:20 -0500http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=187200#post-id-187200Comment by Eduardo for <p>The formulas look correct for me. The corresponding equations are given below.</p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 1 is:
<img alt="Eq1-1" src="/upfiles/15204351195435918.png"></p>
<p><img alt="Eq1-2" src="/upfiles/15204359059777849.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 1 to the frame 2 is:
<img alt="Eq2" src="/upfiles/15204352216040811.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 2 is then:
<img alt="Eq3" src="/upfiles/1520435259800403.png">
<img alt="Eq4" src="/upfiles/15204364024066438.png"></p>
<p>Note that as <code>rvec</code> is a Rodriges rotation vector, <code>rodrigues(rvec)</code> gives the corresponding rotation matrix <code>R</code>.</p>
http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=186386#post-id-186386`rvec3` is the same thing than `2_R_0` but in Rodrigues rotation vector representation. `rvec = rodrigues^-1(R)` means just that the rotation matrix is converted into a rotation vector.Fri, 09 Mar 2018 10:06:58 -0600http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=186386#post-id-186386Comment by bendikiv for <p>The formulas look correct for me. The corresponding equations are given below.</p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 1 is:
<img alt="Eq1-1" src="/upfiles/15204351195435918.png"></p>
<p><img alt="Eq1-2" src="/upfiles/15204359059777849.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 1 to the frame 2 is:
<img alt="Eq2" src="/upfiles/15204352216040811.png"></p>
<p>The transformation that allows converting a 3D point expressed in the frame 0 to the frame 2 is then:
<img alt="Eq3" src="/upfiles/1520435259800403.png">
<img alt="Eq4" src="/upfiles/15204364024066438.png"></p>
<p>Note that as <code>rvec</code> is a Rodriges rotation vector, <code>rodrigues(rvec)</code> gives the corresponding rotation matrix <code>R</code>.</p>
http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=186336#post-id-186336Thanks! Nice explanation, it makes more sense to me now. However, the rvec3 output from composeRT is the (0,0) element of your T²_0 matrix inversed, is it not?Thu, 08 Mar 2018 11:00:09 -0600http://answers.opencv.org/question/186217/composert-inputoutput-question/?comment=186336#post-id-186336