4

I am using the SURF algorithm for comparing landmarks between objects, and am wondering how to detect the rotation angle between the two pictures. I have already seen the another question very similar. This question was turned down for being a naive way to achieve the results. But the results are still achievable through this method.

So my question remains, how can you detect the difference in angle orientation between two images using OpenCV's SURF algorithm (C++ please).

The code i am using can be found from opencv tutorial pages.

Community
  • 1
  • 1
The_Doctor
  • 181
  • 5
  • 16
  • possible duplicate of [scale and rotation Template matching](http://stackoverflow.com/questions/10666436/scale-and-rotation-template-matching) – Fabricator Jun 04 '14 at 05:33
  • do you assume only a rotation, or do you assume a homography (e.g. scale, rotation and translation) but are only interested in the rotation part of the computed homography? – Micka Jun 04 '14 at 07:46

2 Answers2

5

I think, once you get homography matrix H, you can decompose it into its components matrixes: translation, rotation and scale. Here is an example

I suggest you to read this useful tutorial: https://math.stackexchange.com/questions/78137/decomposition-of-a-nonsquare-affine-matrix

Community
  • 1
  • 1
Y.AL
  • 1,808
  • 13
  • 27
0

This is how I did using EmguCv (.NET wrapper to OpenCV) & C#.

Once you get the homography matrix you can get the rotation angle using RotatedRect object.

System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Point.Empty, modelImage.Size);
PointF[] pts = new PointF[]
{
  new PointF(rect.Left, rect.Bottom),
  new PointF(rect.Right, rect.Bottom),
  new PointF(rect.Right, rect.Top),
  new PointF(rect.Left, rect.Top)
};

pts = CvInvoke.PerspectiveTransform(pts, homography);

RotatedRect IdentifiedImage = CvInvoke.MinAreaRect(pts);
result.RotationAngle = IdentifiedImage.Angle;

You can convert above code in C++.

Vipul
  • 1,563
  • 4
  • 22
  • 46