# Relative Position of Two cameras

**URL:** <https://forum.opencv.org/t/relative-position-of-two-cameras/4304>\
**Category:** Python\
**Tags:** calib3d, aruco\
**Created:** [July 12, 2021, 6:08pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304 "2021-07-12T18:08:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Just](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/just/32/2649_2.png) [@Just](https://forum.opencv.org/u/Just)\
**Post date:** [July 12, 2021, 6:08pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304/1 "2021-07-12T18:08:38Z")

</div>

I have two cameras taking images of Aruco markers. I then calculate the pose of each camera for each marker using estimatePoseSingleMarkers and then calculate the relative orientation between the cameras by inverting one of the poses and adding it to the other pose. However, the calculated relative pose of the cameras is different for each marker. why is this so? shouldn’t the relative orientation of the cameras remain constant?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 12, 2021, 6:24pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304/2 "2021-07-12T18:24:24Z")

</div>

some data and code please?

---

<div class="post-metadata">

**Author:** ![Just](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/just/32/2649_2.png) [@Just](https://forum.opencv.org/u/Just)\
**Post date:** [July 12, 2021, 8:43pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304/3 "2021-07-12T20:43:34Z")

</div>

my logic is as follows, given poses of the same target in target frame:  
Pose 1=R1 and T1, Pose2=R2 and T2,

First invert Pose1,

```
      R1_inverse = np.matrix(R).T (invert rotation by transposing it)
      T1_inverse = np.dot(-R_inverse, np.matrix(T1))

```

then Compose inverted Pose1 with Pose2 to get the relative pose of camera 2 from camera 1:

```
       info = cv2.composeRT(R1_inverse, T1_inverse,R2, T2)
      composedRvec, composedTvec = info[0], info[1]

```

the composed R and T should now be the pose of camera 2 from camera 1 and should be the same for every target. Or am I missing something?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 13, 2021, 2:23pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304/4 "2021-07-13T14:23:20Z")

</div>

> [@Just](#):
>
> Or am I missing something?

in principle that sounds correct.

however the math may contain errors, or not.

I would recommend working with 4x4 matrices, always, instead of handling R and T separately. that only leads to headache.

make sure of the sense of each matrix. aruco pose matrices, speaking 4x4, ought to express a transformation from marker frame to the camera frame, or equivalently, they express the marker’s pose in the camera frame.

that’s the typical matrix notation and it helps keep things “type-safe” when composing (multiplying).

\begin{align\*} ^\text{destination frame} ~ &T ~ \_\text{source frame} \\ ^\text{camera frame} ~ &T ~ \_\text{marker frame} \\ \end{align\*}

---

<div class="post-metadata">

**Author:** ![Just](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/just/32/2649_2.png) [@Just](https://forum.opencv.org/u/Just)\
**Post date:** [July 13, 2021, 10:24pm UTC](https://forum.opencv.org/t/relative-position-of-two-cameras/4304/5 "2021-07-13T22:24:33Z")

</div>

THanks. I will try that and see how it goes. Cheers
