【发布时间】:2015-03-24 18:28:57
【问题描述】:
我正在尝试在不同的图像中找到硬币并标记它们的位置。硬币总是完美的圆形(不是椭圆),但它们可以接触甚至重叠。 Here 是一些示例图像,以及我尝试的结果(使用 skimage 及其输出的 Python 脚本),但它似乎表现不佳。
脚本:
def edges(img, t):
@adapt_rgb(each_channel)
def filter_rgb(image):
sigma = 1
return feature.canny(image, sigma=sigma, low_threshold=t/sigma/2, high_threshold=t/sigma)
edges = color.rgb2hsv(filter_rgb(img))
edges = edges[..., 2]
return edges
images = io.ImageCollection('*.bmp', conserve_memory=True)
for i, im in enumerate(images):
es = edges(im, t=220)
output = im.copy()
circles = cv2.HoughCircles((es*255).astype(np.uint8), cv2.cv.CV_HOUGH_GRADIENT, dp=1, minDist=50, param2=50, minRadius=0, maxRadius=0)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
# now es is edges
# and output is image with marked circles
几个示例图像,检测到边缘和圆圈:
我正在使用精明的边缘检测和霍夫变换,这是检测圆的最常用方法。但是,使用相同的参数,它在某些照片上几乎找不到任何东西,而在其他照片上却发现了太多的圆圈。
你能给我一些关于如何更好地做到这一点的指示和建议吗?
【问题讨论】:
-
我个人不知道,但我曾经看到过这个问题:stackoverflow.com/questions/22460651/detecting-truck-wheels。也许它可以帮助你?
-
我收藏中的@JoJo 图像可能具有不均匀的亮度,因此甚至没有考虑阈值(在那里的答案中使用)。不过,会尝试一下(可能是一些自适应版本)。
-
houghcircles 在内部使用 canny。请使用灰度图像作为输入,而不是边缘图像!
-
只是将我的 answer 重新编辑为评论。检查this scikit-image 中的帖子!
标签: opencv computer-vision geometry hough-transform scikit-image