OpenCV's RotatedRect angle does not provide enough information

后端 未结 4 2007
囚心锁ツ
囚心锁ツ 2020-12-29 12:41

From my experiments, the angle returned by RotatedRect\'s angle variable goes from -90 to 0 degrees, which is not sufficient to determine if the object is leaned to the left

4条回答
  •  悲&欢浪女
    2020-12-29 13:00

    After learning from Sebastian Schmitz and Michael Burdinov answers this is how I solved it:

    RotatedRect rotated_rect = minAreaRect(contour);
    float blob_angle_deg = rotated_rect.angle;
    if (rotated_rect.size.width < rotated_rect.size.height) {
      blob_angle_deg = 90 + blob_angle_deg;
    }
    Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);
    

    So, in fact, RotatedRect's angle does not provide enough information for knowing an object's angle, you must also use RotatedRect's size.width and size.height.

提交回复
热议问题