# Which SolvePnp method returns the most accurate translation and rotation?

**URL:** <https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834>\
**Category:** Python\
**Tags:** calib3d, solvepnp, calibration\
**Created:** [May 18, 2022, 4:06pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834 "2022-05-18T16:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [May 18, 2022, 4:06pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/1 "2022-05-18T16:06:47Z")

</div>

I am trying to do hand in eye calibration with my robot however I am my transformation matrix is not very precise and has a large offshoot in translation, which I think I can fix with offshoots but I want to fix calibration. I think the error is from solvepnp. I have some questions:

Which SolvePnp method returns the most accurate translation and rotation?

When I pass my rotation I convert it to 3x3 rotation with cv2.rodrigues. Should I have done anything else?

The lines are colinear and I don’t have time constraints.

```
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30000000, 0.00000001)

```

I also use the line above

---

<div class="post-metadata">

**Author:** ![Eduardo](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@Eduardo](https://forum.opencv.org/u/Eduardo)\
**Post date:** [May 19, 2022, 7:15pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/2 "2022-05-19T19:15:46Z")

</div>

To understand, are you using this function for hand-eye calibration?

- [`calibrateHandEye()`](https://docs.opencv.org/4.5.5/d9/d0c/group__calib3d.html#gaebfc1c9f7434196a374c382abf43439b)

It looks a little bit odd for me that `SolvePnP()` alone would lead to large inaccuracies. For me, it could be something like not enough variations in the robot poses, or maybe bad camera calibration?

---

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [May 20, 2022, 6:21pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/3 "2022-05-20T18:21:49Z")

</div>

Yes it is \* [`calibrateHandEye()`](https://docs.opencv.org/4.5.5/d9/d0c/group__calib3d.html#gaebfc1c9f7434196a374c382abf43439b).  
We found out too late the reason it did not work was that we assumed that the camera coordinates and the camera coordinates from opencv was aligned…

The functioned worked as it should we just made a mistake.

Quick question to make sure about handeye(). I have to make the base2gripper transformation inverse when it is eye to hand transformation I am looking for and when it is eye in hand I should not take the inverse when using the function right?

---

<div class="post-metadata">

**Author:** ![Eduardo](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@Eduardo](https://forum.opencv.org/u/Eduardo)\
**Post date:** [May 20, 2022, 7:31pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/4 "2022-05-20T19:31:16Z")

</div>

> I have to make the base2gripper transformation inverse when it is eye to hand transformation

Yes.

Have also a look at this test: [opencv/modules/calib3d/test/test\_calibration\_hand\_eye.cpp at 50e8ad285b6fcf388c4283b2c433aac099a6562c · opencv/opencv · GitHub](https://github.com/opencv/opencv/blob/50e8ad285b6fcf388c4283b2c433aac099a6562c/modules/calib3d/test/test_calibration_hand_eye.cpp#L475-L515)  
for a complete example.

---

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [May 22, 2022, 8:51pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/5 "2022-05-22T20:51:22Z")

</div>

I want to find a target with my camera. I need the transformation T\_B^t= where B is the base and t is the target (i.ie the target in the base frame). From the function hand-eye() I get the transformation T\_C^G. The other matrices that exist is the T\_C^t which is the target in the camera frame and the T\_B^G transformation from base to gripper. To get the target is this the correct formula?

{T\_C^G}^{-1}=T\_G^C  
T\_B^T=T\_B^G\cdot T\_G^C \cdot T\_C^t

In the code I found this line:

```
    Mat T_base2cam = homogeneousInverse(T_cam2gripper) * homogeneousInverse(T_gripper2base);

```

However, I dont get the order and the inverse and i am not sure if this is the one i am looking for. Where is the eye in hand part?

I tried the one from the code and it looks like It might be what I am looking for. Is it possible that you can explain it? Why am I wrong?

---

<div class="post-metadata">

**Author:** ![Eduardo](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@Eduardo](https://forum.opencv.org/u/Eduardo)\
**Post date:** [May 23, 2022, 6:07pm UTC](https://forum.opencv.org/t/which-solvepnp-method-returns-the-most-accurate-translation-and-rotation/8834/6 "2022-05-23T18:07:26Z")

</div>

Eye-in-Hand configuration is the following:

![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/4b59652f2edec06fa0cdb19a7bff0c88998a85b9.png)

The eye-in-hand calibration allows you to estimate the transformation between the camera and the robot end-effector.

If you have the pose of an object of interest with respect to the camera frame, you can transform it to have its pose with respect to the robot end-effector frame. Then, using the pose of the robot end-effector with respect to the robot base frame, you can have the pose of the object with respect to the robot base frame.

The pose of the robot end-effector with respect to the robot base frame can be retrieved using the robot kinematic model: using the current joint positions give you the pose of the end-effector with respect to the robot base frame.

* * *

Eye-to-hand configuration is the following:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/0dbadb03e47e98ba6e4ac553d889e1d7697b8ade.png)

The camera is static with respect to the robot base frame.
