c# - 在 Emgu.CV 中,这些阈值是什么意思,是否有更好的方法来检测圆?

标签 c# emgucv edge-detection

背景

这是我的 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);

这是图片:

Image of circles

问题

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

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

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

谢谢

最佳答案

  • accumulator 是必须“累积”多少点才能被视为 圆圈。数字越大,检测到的圆圈越少。
  • 分辨率如何 关闭点必须是建议的圆圈。基本上是 像素的“大小”。
  • MinDistance 是圆允许的距离 成为彼此。在您的示例中,您有 3 个圆圈 彼此靠近。增加最小距离会阻止 重叠的圆圈,而不是只画一个。

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

关于c# - 在 Emgu.CV 中,这些阈值是什么意思,是否有更好的方法来检测圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5517926/

相关文章:

c# - 如何填充 ToolStripComboBox?

c# - 如何清除点图中的绘制值?

c# - Emgu OpenCV Intptr 到 IplImage?

c# - 如何使用 C# 在没有任何循环的情况下打印 1 到 100

c# - 减少重复代码

c# - 将高斯模糊应用于频域图像

c# - Emgu CV 不检测 CUDA

python - 在这种情况下我应该使用哪种图像质量指标(二值分割图像)?

android - 无论颜色如何,如何获得明确定义的边缘

python - 图像处理Opencv Python中的角点检测