Reputation: 503
Hy guys, I need to find the coordinates of the center of the small circles inside in an image. I don't want to use the Hought method of cv. Every circle has radius of 20 pixels.
The image is like this:
I read the image in grayscale because I want e value normalized between 0-255.
This is the code, I can't find where I wrong:
img = cv2.imread('input_image',0)#read in grayscale
lista = []
rows,cols = img.shape
for i in range(rows):
for j in range(cols):
k = img[i,j]
if k == 0:
#No circle
continue
else:
#Circle
x=i+10
y=j
k = img[x,y]#centro del pallino
i+=21
arr = np.array([x,y,k])
lista.append(arr)
print(lista)
I would to have a list of arrays, where each arrays contains the x coordinate, the y coordinate and the value of pixel. Where i wrong?
Upvotes: 0
Views: 788
Reputation: 98
Since the top most point of the circle will be encountered for the first time in the for-loop, x and y values should be updated as x=i
and y = j+10
.
Also, this logic would not work if there were two circles such that the line joining centers of the two circles is nearly horizontal.
Upvotes: 1