-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
minAreaRect angle calculation fails with a particular contour #19769
Copy link
Copy link
Closed
Labels
Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/https://opencv.org/opencv-hackathon-starts-next-week/affected: 3.4bugcategory: imgprocconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete
Milestone
Description
System information (version)
- OpenCV => 4.5.1.48
- Operating System / Platform => Ubuntu 20.04
- Compiler => Python3.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. This should have been fixed with !18157 but now happens again. Please note that it is important to use the contour provided in the .txt file.
Steps to reproduce
Python code:
contour = np.loadtxt("defect_contour.txt").reshape(-1, 1, 2).astype(np.int32)
rect = cv.minAreaRect(contour)
box = cv.boxPoints(rect)
box = np.int0(box)
out = np.zeros((3000, 3000, 3))
cv.drawContours(out,[box],-1,(0,255,0),2)
cv.drawContours(out,[contour],-1,(255,0,0),2)
cv.imwrite("defect_contour.png", out)
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,
forum.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/affected: 3.4bugcategory: imgprocconfirmedThere is stable reproducer / investigation completeThere is stable reproducer / investigation complete