Skip to content

Anti-aliasing error when drawing circles #16308

Closed

Description

@bramstoeller

When I try to draw an anti-aliased circle in Python 3 (OpenCV 4.2.1.30) the border is incorrect. I have no idea what could have gone wrong... anyone?

img = np.zeros((101, 101), dtype=np.uint8)
cv2.circle(img, (50, 50), 50, 255, cv2.FILLED, cv2.LINE_AA)
cv2.imwrite("circle.png", img)

This is the result (4x zoom), the issue is most noticable at the top and bottom of the circle, but the sides don't look too smooth too...

circle

EDIT: The issue is even clearer in a non-filled circle; it is missing parts of the circumference entirely.

cv2.circle(img, (50, 50), 50, 255, 1, cv2.LINE_AA)

circle

P.S. I'm getting the same result on both Linux and Windows.

Activity

  1. bramstoeller commented on Jan 10, 2020

    @bramstoeller
    Author

    I found out that it only occurs if the canvas is just big enough to fit the circle and only when using anti-aliased lines:

    img = np.zeros((25, 25), dtype=np.uint8)
    cv2.circle(img, (12, 12), 11, 255, 1, cv2.LINE_8)

    circle_25_11_8

    img = np.zeros((25, 25), dtype=np.uint8)
    cv2.circle(img, (12, 12), 11, 255, 1, cv2.LINE_AA)

    circle_25_11_AA

    img = np.zeros((27, 27), dtype=np.uint8)
    cv2.circle(img, (13, 13), 11, 255, 1, cv2.LINE_AA)

    circle_27_11_AA

    The obvious workaround is to use a slightly bigger canvas and then crop it, but I still think it's a bug.

  2. added
    Hackathon
    on Jan 21, 2020
  3. vicdxxx commented on Jan 31, 2020

    @vicdxxx

    Hi @AStone
    I try to trace this Hackathon bug, OpenCV 4.2.1.30 cannot install from pip, what is the way you install this version?

  4. vpisarev commented on Feb 3, 2020

    @vpisarev
    Contributor

    @vicdxxx, if you are going to work on this issue, you will need to clone opencv in your github account, then git clone it, make a branch etc. I believe, it will be much easier to try to reproduce this problem with C++ code and then debug it. Debugging mixed C++ + Python code is very inconvenient

  5. self-assigned this
    on Feb 3, 2020
  6. bramstoeller commented on Feb 6, 2020

    @bramstoeller
    Author

    @vpisarev Thanks for fixing this so soon! It saves me a lot of fumbling around with extra margins in my application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Hackathonbugcategory: imgprocconfirmed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions