Не могли бы вы показать мне код?
у сделать обнаружение окружности при условии, что: перекрывающиеся круги будут считаться как 1 кружок.
В частности, когда я делаю обнаружение окружности и помещаю букву «P» в каждый кружок (на самом деле они являются пыльцой или окружающими их объектами) для изображения ниже
Это стало
(Та же фотография, но я не знаю, почему она стала горизонтальной, когда я загрузил ее здесь)
Но я просто хочу 1 букву P для каждого круга. Регулировка радиуса может быть хорошей идеей, но у меня еще есть много других фотографий, поэтому я надеюсь, что есть способ игнорировать наложение.
Вот мой код:
import cv2
import numpy as np
path = "./sample.JPG"
font = cv2.FONT_HERSHEY_COMPLEX
def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
# initialize the dimensions of the image to be resized and
# grab the image size
dim = None
(h, w) = image.shape[:2]
# if both the width and height are None, then return the
# original image
if width is None and height is None:
return image
# check to see if the width is None
if width is None:
# calculate the ratio of the height and construct the
# dimensions
r = height / float(h)
dim = (int(w * r), height)
# otherwise, the height is None
else:
# calculate the ratio of the width and construct the
# dimensions
r = width / float(w)
dim = (width, int(h * r))
# resize the image
resized = cv2.resize(image, dim, interpolation = inter)
# return the resized image
return resized
# In[22]:
iml = cv2.imread(path,cv2.IMREAD_COLOR)
img = image_resize(iml,width=960)
cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cimg = cv2.medianBlur(cimg,5)
#Circle detection to detect pollen in big images, return the center's coordinates and radius of circles in array
circles = cv2.HoughCircles(cimg,cv2.HOUGH_GRADIENT,1,10,param1=15,param2=20,minRadius=10,maxRadius=25)
circles = np.uint16(np.around(circles))[0,:]
for i in circles:
cv2.putText(img,'P',(i[0],i[1]), font, 0.5,(0,0,255),1,cv2.LINE_AA)
cv2.imwrite("./output.jpg",img)