我想在以下条件下进行圆检测:重叠圆将计为 1 个圆。
Particularly, when I do circle detection and put the letter "P" to every circle (actually they are pollen, or circle-like objects) for the image below
![enter image description here](https://i.stack.imgur.com/032OR.jpg)
它变成了
![enter image description here](https://i.stack.imgur.com/gbnAK.jpg)
(同一张照片,但我不知道为什么当我上传到这里时它变成了水平)
但我只想每个圆圈有 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)