Вот решение с использованием scikit-image
Hough-transform. Используя следующий код, вы можете обнаружить круги, найти центры и радиусы (вы можете использовать соответствующие функции cv2
аналогичным образом):
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color, io
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
from skimage.draw import circle_perimeter
from skimage.util import img_as_ubyte
image = color.rgb2gray(img_as_ubyte(io.imread('new images/FjOll.png')))
edges = canny(image, sigma=1)
hough_radii = [6] # detect circles of radius 6
hough_res = hough_circle(edges, hough_radii)
# select most prominent 25 circles
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii, total_num_peaks=20)
# Draw circles
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(10, 4))
image = color.gray2rgb(image)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius)
print(center_y, center_x, radius)
image[circy, circx] = (255, 0, 0)
ax.imshow(image)
plt.show()
## detected circles: (center_y, center_x, radius)
# (171, 103, 6)
# (56, 38, 6)
# (16, 99, 6)
# (141, 128, 6)
# (126, 32, 6)
# (95, 159, 6)
# (120, 90, 6)
# (56, 96, 6)
# (57, 157, 6)
# (120, 158, 6)
# (140, 62, 6)
# (108, 64, 6)
# (77, 64, 6)
# (42, 68, 6)
# (106, 130, 6)
# (73, 128, 6)
# (38, 127, 6)
# (75, 130, 6)
# (88, 38, 6)
# (86, 93, 6)