user349026
user349026

Reputation:

Rotate rectangles - ANGLE returned - Opencv

I have a problem understanding how OpenCV works when it comes to RotatedRect.

I have extracted a contour and I then try to fit a rotated rectangle over it. The angles that I keep getting range only in 0 to -90. Even if I have the contour directing the other way by flipping it, I still get 0 to -90 angles.

My problem is to make sure the contour lies at 0' degrees. And for that I have to calculated the orientation and then rotate accordingly.

How are these angles represented in OpenCV (2.4.3)?

Regards Wajih

Upvotes: 2

Views: 3985

Answers (2)

shanif
shanif

Reputation: 464

i found out that the angle is between the counter and Y axis (from LearningOpenCV) .are you expecting it to be from X axis?

Upvotes: 1

krzych
krzych

Reputation: 2176

In some cases RotatedRect angle can be the same for contour rotated 180 deg. The best way to figure out if it happens in your case is to draw fitted RotatedRect.

I think that more suited for your case are contour moments.

See my answers there: Rotation and scale invariant template matching in OpenCV and there: Find the orientation of an image

You can compute moments with cv::Moments : http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#cv.Moments

Upvotes: 1

Related Questions