I want to do circle detection under the condition that: overlap circles will be count as 1 circle.
Particularly, when I do circle detection and put the letter \"P\" to e
I would suggest using contours instead. However, if you do want to use HoughCircles, look at the 4th parameter in the function. Changing this, I could get rid of the overlappings. Additionally, I tweaked a bit the parameters for canny threshold in the HoughCircles function until I got the desired results. I'd suggest understanding the parameters well before coming up with a conclusion.
Code:
import cv2
import numpy as np
arr = cv2.imread("U:/SO/032OR.jpg")
print(arr.shape)
imggray = cv2.cvtColor(arr, cv2.COLOR_BGR2GRAY)
# Not median blur
imggray = cv2.GaussianBlur(imggray, (9,9),3)
circles_norm = cv2.HoughCircles(imggray, cv2.HOUGH_GRADIENT, 1, imggray.shape[0]/16,
param1=20, param2=8, minRadius=15, maxRadius=30)
circles_norm = np.uint16(np.around(circles_norm))[0,:]
for i in circles_norm:
center = (i[0], i[1])
cv2.putText(arr, 'P', (i[0], i[1]), cv2.FONT_HERSHEY_COMPLEX, 0.5,
(0,0,255),1,cv2.LINE_AA)
Result:
(1) Threshold using OTSU and then adjust the thresh vaule again
(2) Find the external contours on the binary image, filter the contour by area, then find the minClosingCircle.
This is it:
If I was doing this I wouldn't use HoughCircles but instead try:
1) Smooth, to get rid of some noise
2) Threshold, to produce a binary mask
3) Contour, where each contour is a detected pollen.
Simple but I think it should work.