Niko
Niko

Reputation: 26730

Compute transformation matrix from a set of coordinates (with OpenCV)

I have a small cube with n (you can assume that n = 4) distinguished points on its surface. These points are numbered (1-n) and form a coordinate space, where point #1 is the origin.

Now I'm using a tracking camera to get the coordinates of those points, relative to the camera's coordinate space. That means that I now have n vectors p_i pointing from the origin of the camera to the cube's surface.

With that information, I'm trying to compute the affine transformation matrix (rotation + translation) that represents the transformation between those two coordinate spaces. The translation part is fairly trivial, but I'm struggling with the computation of the rotation matrix.

Is there any build-in functionality in OpenCV that might help me solve this problem?

Upvotes: 0

Views: 3465

Answers (3)

Ankur Kumar
Ankur Kumar

Reputation: 46

Look at the Stereo Camera tutorial for OpenCV. OpenCV uses a planar chessboard for all the computation and sets its Z-dimension to 0 to build its list of 3D points. You already have 3D points so change the code in the tutorial to reflect your list of 3D points. Then you can compute the transformation.

Upvotes: 1

fireant
fireant

Reputation: 14530

solvePnP should give you the rotation matrix and the translation vector. Try it with CV_EPNP or CV_ITERATIVE.

Edit: Or perhaps you're looking for RQ decomposition.

Upvotes: 1

Josh Bleecher Snyder
Josh Bleecher Snyder

Reputation: 8432

Sounds like cvGetPerspectiveTransform is what you're looking for; cvFindHomograpy might also be helpful.

Upvotes: 1

Related Questions