Julio
Julio

Reputation: 155

OpenCV - How to detect and measure an angle between two frames?

I'm trying to understand and use OpenCV. I wanted to know if it is possible to find and measure an angle between two frames.

I explain : The cam is fix and the frames could rotate around the center and won't move. For now I managed to rotate manually and I would like to be able to compare frames and return the angle. For instance :

double getRotation(Image img1, Image img2) {
  //Compare the frames

  //Return the value
}

and then I rotate following that angle.

Upvotes: 5

Views: 3472

Answers (2)

user349026
user349026

Reputation:

Well this might be very tricky, just a simpler solution might be to find the hough lines of the frames. Of course you would need to determined where the best and stable lines are which you can track between the two frames, once that is available, you can then find the angle between the two frames. What Andrey has suggested for finding the angles should be usable as well.

Upvotes: 0

Andrey Sboev
Andrey Sboev

Reputation: 7672

If you're able to detect static objects, e. g. background, on the frames then you may find points called good_features_to_track (cvGoodFeaturesToTrack) on the background and track this points using optical_flow (cvCalcOpticalFlowPyrLK).

If rotation is only on 'xy' plain you're able to detect rotation using cvGetAffineTransform.

Since only rotation is allowed (no translation and scaling) it's not difficult to determine an angle of rotation using transformation matrix, obtained by cvGetAffineTransform. That matrix looks like (see wikipedia):

enter image description here

Where \theta is the rotation angle

Upvotes: 3

Related Questions