Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotation matrix openCV

Tags:

math

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?

like image 445
Mario Avatar asked Dec 19 '10 23:12

Mario


People also ask

What is a rotation matrix in OpenCV?

getRotationMatrix2D() function is used to make the transformation matrix M which will be used for rotating a image. Syntax: cv2.getRotationMatrix2D(center, angle, scale)

What is rotation matrix in image processing?

Indeed, a rotation matrix can be seen as the trigonometric summation angle formulae in matrix form. One way to understand this is say we have a vector at an angle 30° from the x axis, and we wish to rotate that angle by a further 45°. We simply need to compute the vector endpoint coordinates at 75°.

What is cv warpAffine?

Code We use the function cv::warpAffine for that purpose. Applies a Rotation to the image after being transformed. This rotation is with respect to the image center. Waits until the user exits the program.


1 Answers

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.

like image 123
Marcelo Cantos Avatar answered Oct 07 '22 21:10

Marcelo Cantos