-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
minAreaRect angle calculation fails with a particular contour #18157
Copy link
Copy link
Closed
Labels
Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/https://opencv.org/opencv-hackathon-starts-next-week/bugcategory: imgprocconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete
Milestone
Description
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
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
answers.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/https://opencv.org/opencv-hackathon-starts-next-week/bugcategory: imgprocconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete