Mario
Mario

Reputation: 1469

Rotation matrix openCV

I would like to know how to find the rotation matrix for a set of features in a frame. I will be more specific. I have 2 frames with 20 features, let's say frame 1 and frame 2. I could estimate the location of the features in both frames. For example let say a certain frame 1 feature at location (x, y) and I know exactly where it is so let's say (x',y').

My question is that the features are moved and probably rotated so I wanna know how to compute the rotation matrix, I know the rotation matrix for 2D:

alt text

But I don't know how to compute the angle, and how to do that? I tried a function in OpenCV which is cv2DRotationMatrix(); but the problem which as I mentioned above I don't know how to compute the angle for the rotation matrix and another problem which it gives 2*3 matrix, so it won't work out cause if I will take this 20*2 matrix, (20 is the number of features and 2 are the location in (x,y)) and multiply it by the matrix by 2*3 which is the results from the function then I will get 20*3 matrix which it doesn't seem to be realistic cause I'm working with 2D.
So what should I do? To be more specific again, show me how to compute the angle to use it in the matrix?

Upvotes: 6

Views: 3786

Answers (2)

Utkarsh Sinha
Utkarsh Sinha

Reputation: 3305

Have a look at this function:

cvGetAffineTransform

You give it three points in the first frame and three in the second. And it computes the affine transformation matrix (translation + rotation)

If you want, you could also try

cvGetPerspectiveTransform

With that, you can get translation+rotation+skew+lot of others.

Upvotes: 3

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

I'm not sure I've understood your question, but if you want to find out the angle of rotation resulting from an arbitrary transform...

A simple hack is to transform the points [0 0] and [1 0] and getting the angle of the ray from the first transformed point to the second.

o = M • [0 0]
x = M • [1 0]
d = x - o
θ = atan2(d.y, d.x)

This doesn't consider skew and other non-orthogonal transforms, for which the notion of "angle" is vague.

Upvotes: 6

Related Questions