# What is the reference vector in OpenCV for 3D rotation?

**URL:** <https://forum.opencv.org/t/what-is-the-reference-vector-in-opencv-for-3d-rotation/14757>\
**Category:** Android/Java\
**Tags:** calib3d\
**Created:** [October 5, 2023, 11:39am UTC](https://forum.opencv.org/t/what-is-the-reference-vector-in-opencv-for-3d-rotation/14757 "2023-10-05T11:39:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vatbub](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@vatbub](https://forum.opencv.org/u/vatbub)\
**Post date:** [October 5, 2023, 11:39am UTC](https://forum.opencv.org/t/what-is-the-reference-vector-in-opencv-for-3d-rotation/14757/1 "2023-10-05T11:39:35Z")

</div>

I tried to [post this question on StackOverflow](https://stackoverflow.com/questions/77150389/what-is-the-reference-vector-in-opencv-for-3d-rotation), but it seems to cause confusion over there, so I am attempting my luck here again:  
I have a multi-camera system where the cameras are mounted to a fixed structure (except for wind-induced vibration, the cameras are not moving). I measured the position and the orientation of the cameras with a total station, which means that I have a rough estimate of the translation vectors and the (what I call) camera’s forward vector (vector pointing from the sensor’s principal point out the front of the camera).

Using the total station, I also measured the 3D position of a couple of markers, and I am now trying to get an extrinsic camera calibration using `Calib3D.calibrateCamera()`.

Sidenote: I did do a separate intrinsic calibration, so we are only talking about the extrinsic parameters `tvec` and `rvec` here.

At first, I tried to run `calibrateCamera()` without any initial values for the extrinsic parameters, but the results were obvious garbage (OpenCV estimated that the cameras must be several km below the ground). I therefore would like to give `calibrateCamera()` the initial guess that I measured using the total station for `tvec` and `rvec`, but I am struggling to convert my forward vector into a Rodrigues vector.

Here’s a figure to illustrate how I understand the situation:

 ![grafik](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d6eaa131373690c34d938072be2853d68672597b.png)

My camera is looking into the direction of `v_cam`, so, `v_cam` is the aforementioned “forward vector”. Given some reference vector `v_Ref`, the Rodrigues vector `v_Rodrigues` defines the rotation axis around which `v_Ref` is rotated and through its length, `v_Rodrigues` defines by what angle `v_Ref` needs to be rotated to result in `v_cam`.

So, given that I (roughly) know `v_cam`, I would like to construct `v_Rodrigues` by calculating the cross-product of `v_cam` and `v_Ref` and scaling the result by the angle between `v_Ref` and `v_cam`.

Now, the two questions that I have are:

1. Is my understanding of the math correct?
2. How does OpenCV define `v_Ref`?

The second question could also be rephrased as: “If the rotation were to be represented by a rotation matrix, what direction would the camera be pointing in if the rotation matrix is an identity matrix?”

Cheers, and thank you for your help 🙂

---

<div class="post-metadata">

**Author:** ![vatbub](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@vatbub](https://forum.opencv.org/u/vatbub)\
**Post date:** [October 5, 2023, 6:27pm UTC](https://forum.opencv.org/t/what-is-the-reference-vector-in-opencv-for-3d-rotation/14757/2 "2023-10-05T18:27:53Z")

</div>

Thanks to the comments on StackOverflow, I did end up finding a solution that seems correct, but I cannot yet entirely explain why 🙈 So, feel free to [read what I found](https://stackoverflow.com/a/77239699/5736633) and if you have any idea why things are the way they are, please leave a comment on StackOverflow or here in the forum as I would love to get a full understanding of this.
