2

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

Charles
  • 50,943
  • 13
  • 104
  • 142
  • related to https://stackoverflow.com/questions/15956124/minarearect-angles-unsure-about-the-angle-returned – jdhao Dec 19 '18 at 13:04

2 Answers2

1

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

Community
  • 1
  • 1
krzych
  • 2,126
  • 7
  • 31
  • 50
1

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

shanif
  • 464
  • 1
  • 4
  • 12