System information (version)
- OpenCV => 4.2
- Operating System / Platform => Ubuntu 18.04
- Compiler => Python 3.8
Detailed description
minAreaRect is supposed to provide an angle as part of a rotated bounding box of a contour. It works fine in most cases, but I encountered multiple cases where a wrong angle is returned. I first saw this issue when using the python implementation, but can confirm this is also happening in C++.
Steps to reproduce
Python code:
contour = np.loadtxt("defect_contour.txt").reshape(-1, 1, 2).astype(np.int32)
rect = cv.minAreaRect(contour) # xy, wh, angle
box = cv.boxPoints(rect) # cv2.boxPoints(rect) for OpenCV 3.x
box = np.int0(box)
cv.imwrite("defect_contour.png", cv.drawContours(np.zeros((2208, 3216)),[box, contour],-1,255,5))
Using this contour:
defect_contour.txt
The resulting image will look like this:

Issue submission checklist
System information (version)
Detailed description
minAreaRect is supposed to provide an angle as part of a rotated bounding box of a contour. It works fine in most cases, but I encountered multiple cases where a wrong angle is returned. I first saw this issue when using the python implementation, but can confirm this is also happening in C++.
Steps to reproduce
Python code:
Using this contour:
defect_contour.txt
The resulting image will look like this:

Issue submission checklist
answers.opencv.org, Stack Overflow, etc and have not found solution