Skip to content

minAreaRect angle calculation fails with a particular contour #19769

@AnikaP

Description

@AnikaP
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:
defect_contour

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

Metadata

Metadata

Labels

Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/affected: 3.4bugcategory: imgprocconfirmedThere is stable reproducer / investigation complete

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions