问题描述
所以我有一些图像需要从中提取白色圆圈的数量(准确度为 +90%),到目前为止我已经想出了这个
original image(has 183 circles)
and here's the result I get with my code
如你所见,它可以检测到大约一半,但它不是那么准确
目前的代码:
def check_for_cells(img):
found = 0
found_list = []
img = cv2.imread(img,cv2.IMREAD_COLOR)
width,height = img.shape[:2]
img = cv2.resize(img,(int(width/2),int(height/3)))
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray,(15,15),0)
histo_norm = cv2.equalizeHist(blurred)
_,th = cv2.threshold(blurred,121,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
min_dist = 20
param1 = 95
param2 = 18
minRadius = 3
maxRadius = 14
circles = cv2.HoughCircles(histo_norm,cv2.HOUGH_GRADIENT,1,min_dist,param1=param1,param2=param2,minRadius=minRadius,maxRadius=maxRadius)
circles_th = cv2.HoughCircles(th,param1=79,param2=12,maxRadius=maxRadius)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(img,(i[0],i[1]),i[2],(0,0),2)
found_list.append([(i[0],i[2]])
found += 1
if circles_th is not None:
circles_th = np.uint16(np.around(circles_th))
for i in circles_th[0,:]:
if [(i[0],i[2]] not in found_list:
cv2.circle(img,2)
found_list.append([(i[0],i[2]])
found += 1
font = cv2.FONT_HERShey_SIMPLEX
cv2.putText(img,str(found),100),font,4,10)
# print(found)
cv2.namedWindow('img',cv2.WINDOW_norMAL)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
对改进代码的任何帮助将不胜感激!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)