Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jagged edges around the circle in OpenCV - Python

Tags:

python

opencv

As the title says, I am trying to fix the jagged edges around the circle I created in OpenCV.

I've tried a few things i.e. cv2.blur(), cv2.filter2D(), they didn't do the trick.

import numpy as np
import cv2
import random

for i in range(5):
    img = np.zeros((512,512,3), np.uint8)
    H = random.choice(list(range(100,500)))
    V = random.choice(list(range(100,500)))
    S = random.choice(list(range(30,150)))

    cv2.circle(img,(H,V), S, (0,0,255), -1)

    img = cv2.resize(img,(750,750))
    f = (3-len(str(i)))*'0'+str(i)
    cv2.imwrite('circle%s.jpg' % f, img)

cv2.destroyAllWindows()

enter image description here

like image 457
Joe T. Boka Avatar asked Oct 26 '25 18:10

Joe T. Boka


1 Answers

I think you are looking to draw an antialiased outline. You can do that by setting the lineType parameter:

cv2.circle(img,(H,V), S, (0,0,255), -1, lineType=cv2.LINE_AA)
like image 125
w-m Avatar answered Oct 29 '25 08:10

w-m



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!