I'm trying to draw a concurrent circles of equal radius on top row of image with a text on center of circle. I'm able to draw a single circle on center of image as shown below
I used below code to achieve this
import cv2
import numpy as np
img = np.zeros((128, 128, 3), dtype=np.uint8)
h,w = img.shape
CENTER = (64, 64)
cv2.circle(img, CENTER, 48, (127,0,127), -1)
TEXT_FACE = cv2.FONT_HERSHEY_DUPLEX
TEXT_SCALE = 0.5
TEXT_THICKNESS = 2
TEXT = "hello"
text_size, _ = cv2.getTextSize(TEXT, TEXT_FACE, TEXT_SCALE, TEXT_THICKNESS)
text_origin = (int(CENTER[0] - text_size[0] / 2), int(CENTER[1] text_size[1] / 2))
cv2.putText(img, TEXT, text_origin, TEXT_FACE, TEXT_SCALE, (127,255,127), TEXT_THICKNESS, cv2.LINE_AA)
like this I'm trying to draw a circles next to each other on top of image as below
if I give n number of circles how can I find center of them and draw circles like above ?
Any help or suggestions on solving this will be highly appreciated
CodePudding user response:
I haven't added the text. I hope you can do that.
import cv2
img = cv2.imread('Resources/black.jpg')
# Height, Width, Channel
dimension = img.shape
width = dimension[1]
height = dimension[0]
#Drawing circle
r = 20
no_of_possible_circles = int(width//(2*r))
stepper = 1
for i in range(0,no_of_possible_circles,):
cv2.circle(img,(stepper*r,r),r,(0,0,255),cv2.FILLED)
stepper = 2
cv2.imshow("Image",img)
cv2.waitKey(0)
We increase the stepper by '2' because
- center of 1st circle 'll be at (r,r)
- center of 2nd circle 'll be at (3r,r)
- center of 3rd circle 'll be at (5r,r) . . . and so on
This is the result I got