【问题标题】:In Emgu.CV what do these threshold values mean and is there a better way to detect a circle?在 Emgu.CV 中,这些阈值是什么意思,是否有更好的方法来检测圆圈?
【发布时间】:2011-04-01 19:28:14
【问题描述】:

背景

这是我的 Emgu.CV 代码,用于获取图像并绘制其中找到的圆圈(主要来自 Emgu.CV.Examples 解决方案中 ShapeDetection 项目的代码,EmguCV 下载附带):

//Load the image from file
Image<Bgr, Byte> img = new Image<Bgr, byte>(myImageFile);

//Get and sharpen gray image (don't remember where I found this code; prob here on SO)
Image<Gray, Byte> graySoft = img.Convert<Gray, Byte>().PyrDown().PyrUp();
Image<Gray, Byte> gray = graySoft.SmoothGaussian(3);
gray = gray.AddWeighted(graySoft, 1.5, -0.5, 0);

Image<Gray, Byte> bin = gray.ThresholdBinary(new Gray(149), new Gray(255));

Gray cannyThreshold = new Gray(149);
Gray cannyThresholdLinking = new Gray(149);
Gray circleAccumulatorThreshold = new Gray(1000);

Image<Gray, Byte> cannyEdges = bin.Canny(cannyThreshold, cannyThresholdLinking);

//Circles
CircleF[] circles = cannyEdges.HoughCircles(
    cannyThreshold,
    circleAccumulatorThreshold,
    4.0, //Resolution of the accumulator used to detect centers of the circles
    15.0, //min distance 
    5, //min radius
    0 //max radius
    )[0]; //Get the circles from the first channel

//draw circles (on original image)
foreach (CircleF circle in circles)
    img.Draw(circle, new Bgr(Color.Brown), 2);

图片如下:

问题

  1. 好的,所以我知道ThresholdBinary 中的阈值是多少。由于我从灰度图像中获取二进制图像,因此它是图片中灰度的强度。这是因为图片中灰度圆圈的强度为 150 到 185。我认为这与 HoughCircles 的第一个参数相同。

    我不知道的是 circleAccumulatorThreshold、累加器的分辨率和最小距离(到 HoughCircles 的第 2、3 和第 4 个参数)是什么,或者应该有什么值。我显然没有正确的值,因为图片中的圆圈没有正确地'houghed'。

  2. 我的第二个问题是,有没有更好的方法来找到圆圈?我需要能够在多种类型的光线中检测到这个圆圈(即圆圈颜色强度可能很低,如 80 或更低)并在图片中获得它的尺寸。匹配圆圈的最佳方法是什么?我应该让圆圈变成另一种颜色并在原始图像中查找该颜色吗?还有其他想法吗?

谢谢

【问题讨论】:

    标签: c# emgucv edge-detection


    【解决方案1】:
    • 累加器是必须“累积”多少点才能被视为 圆圈。数字越大意味着检测到的圆圈越少。
    • 分辨率如何 关闭点必须要到建议的圈子。基本上 像素的“大小”。
    • MinDistance 是允许的圆圈距离 彼此相待。在您的示例中,您有 3 个圆圈非常 彼此靠近。增加最小距离将阻止 重叠的圆圈,而不是只画一个。

    至于你对第二个的回答,模糊图像,转换为灰度,然后阈值消除照明差异是通常的解决方案

    【讨论】:

      【解决方案2】:

      虽然这个问题已经“很多”老了,但我想对问题 #2 提出一个答案,以帮助那些可能遇到类似问题的人。

      你可以做的是:

      1. 对图像设置阈值以去除背景,
      2. 检测图像中的对象,
      3. 计算圆的圆度(http://en.wikipedia.org/wiki/Shape_factor_(image_analysis_and_microscopy)),如果是圆应该是1。使用 FindContours 方法(在 emgucv 中)提供了计算圆的面积和周长所需的所有信息。然后,您可以使用这些信息来获取检测到的圆圈的尺寸。

      【讨论】:

      • 您建议删除背景什么? @奥利弗
      猜你喜欢
      • 2010-10-24
      • 1970-01-01
      • 2021-04-13
      • 2014-12-09
      • 2013-05-09
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      相关资源
      最近更新 更多