Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there anyway to make circle line in open cv library more direct

I’m trying to draw a circle in a picture using open CV with Python.

Here is the picture I wish I can make :

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the code I write :

import cv2  
import numpy as np  
import imutils

text1 = "10x"  
text2 = "20gr"  

# Load image in OpenCV  
image = cv2.imread('Sasa.jfif')
resized = imutils.resize(image, width=500)
cv2.circle(resized,(350,150),65,(102,51,17),thickness=-1)

# Convert the image to RGB (OpenCV uses BGR)  
cv2_im_rgb = cv2.cvtColor(resized,cv2.COLOR_BGR2RGB)  

# Pass the image to PIL  
pil_im = Image.fromarray(cv2_im_rgb)  

draw = ImageDraw.Draw(pil_im)  
# use a truetype font  
font1 = ImageFont.truetype("arial.ttf", 50)  
font2 = ImageFont.truetype("arial.ttf", 25)  

# Draw the text  
draw.text((310,110), text1, font=font1) 
draw.text((325,170), text2, font=font2) 

# Get back the image to OpenCV  
cv2_im_processed = cv2.cvtColor(np.array(pil_im), cv2.COLOR_RGB2BGR)  

cv2.imshow('Fonts', cv2_im_processed)  
cv2.waitKey(1)  

But this is what my code generate :

enter image description here

The circle line is not precise. Is there anything I can do to make the line preciser or is there any other library that generates circle with precise line ?

Any suggestion will be very appreciated !

>Solution :

You can use anti aliasing to make the circle look better as described here:

cv2.circle(resized,(350,150),65,(102,51,17),thickness=-1,lineType=cv2.LINE_AA)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading