简体   繁体   English

使用霍夫圆变换检测圆阵列

[英]Detecting array of circles using Hough Circle Transform

I am trying to detect all the circles in the array. 我试图检测数组中的所有圆圈。 To achieve this I am using Hough Circle Transform. 为了达到这个目的,我正在使用Hough Circle Transform。 I am able to detect 100% circles in the array but there are a lot many false positives and when I get rid of the false positives I am not able to detect 100% circles. 我能够在阵列中检测到100%的圆圈,但是有很多误报,当我摆脱误报时,我无法检测到100%的圆圈。 When I change the dp parameter to 1 in the code given below then all the false positives are gone and when I keep it as 3 then there are many false positives with 100% detection. 当我在下面给出的代码中将dp参数更改为1时,所有误报都消失了,当我将其保持为3时,则会有很多误报,100%检测。 I would like to get 100% detection with 0 or very few false positives. 我希望100%检测到0或非常少的误报。 What would be the best approach to do this. 这样做的最佳方法是什么。

import cv2
import cv2.cv as cv
import numpy as np

img = cv2.imread('test1.tiff',0)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img, cv.CV_HOUGH_GRADIENT,3,15,
                        param1=70 ,param2=17,minRadius=1,maxRadius=10)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)

cv2.imshow('detected circles',cimg)
cv2.imwrite("output15.jpg", cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

Here there is a sample image: 这里有一个示例图片:

原始图像

没有误报误报

Since they are circles, and all dark, why not filter them out with a morphological disk and subtract the original image from the filtered one to get good responses? 既然它们是圆形的,并且都是黑暗的,为什么不用形态磁盘过滤它们并从过滤后的图像中减去原始图像以获得良好的响应? Morphology isn't particularly fast, but faster than Hough. 形态学不是特别快,但比霍夫快。 What you'd do is dilate the background (with a disk shaped) until the black is gone, then subtract the original image from that. 你要做的是扩大背景(用圆盘形状)直到黑色消失,然后从中减去原始图像。 Then threshold. 然后门槛。 You can then do size filtering to eliminate any tiny scraps that could get through. 然后,您可以进行大小过滤,以消除可能通过的任何微小碎片。

Given this application, I don't think Hough is the strongest choice, unless this is a school project. 鉴于这个应用,我不认为霍夫是最强的选择,除非这是一个学校项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM