# Transform world coordinate to Camera Coordinate using SolvePNP?

I estimate rvec and tvec using solvePNP . How can I convert the (0,0,0) point from world coordinate to the camera coordinate using rvec and tvec? Our model points is shown below:

edit retag close merge delete

Sort by ยป oldest newest most voted

To invert both rvec and tvec, use the following.

Mat R;
Rodrigues(rvec, R);
R = R.t();
tvec = -R*tvec;
Rodrigues(R, rvec);

more

Thank you very much for your answer. Would you clear me, please? After inverting we have to create transformation matrix and multiply it by the homogeneous coordinate of (0,0,0). Is that OK?

( 2017-09-05 21:45:13 -0500 )edit

Clear you?

What you start with is the location of the (0,0,0) point relative to the camera. After you invert rvec and tvec you have the location of the camera relative to the (0,0,0) point and the axes attached to it. What information exactly are you trying to get?

( 2017-09-05 22:14:00 -0500 )edit

Thanks. In the above figure, I have shown an image. the image contains a rectangular object. The model points are also shown in the figure. Now I have estimated the rvec and tvec using SolvePNP. In my experiment, I will move the image to the horizontal axis. After that I want to transform the center point of the rectangle, that means (0,0,0), 3D point, into a 3D points in the camera coordinate system. I want to see the Z value of the transform point, that means the distance between camera and rectagular object.

( 2017-09-06 19:24:27 -0500 )edit

I think you can just use projectPoints() with an identity camera matrix and zero distortion coefficients to transform points in object frame to camera frame.

( 2017-09-07 03:32:47 -0500 )edit

The distance between the camera and the (0,0,0) point is just the norm of the tvec that comes from solvePnP. So sqrt(x^2+y^2+z^2). That is the straight line distance. The distance from the camera focal plane to the point is the z value of the tvec that comes from solvePnP. At least, i think the second one. I'd need to test that.

( 2017-09-07 23:09:01 -0500 )edit

Thanks to all. @ Tetragramm you are right. It is OK now.

( 2017-09-10 05:20:26 -0500 )edit

Official site

GitHub

Wiki

Documentation