opencv - Emgu CV :using HoughCircles detect many nonexistent circles, 等待很长时间

标签 opencv emgucv

原图
original picture 结果图片 result picture

这是我的代码:

private void button3_Click(object sender, EventArgs e)
{
    string strFileName = string.Empty;
    OpenFileDialog ofd = new OpenFileDialog();
    if (ofd.ShowDialog() == DialogResult.OK)
    {
        Image<Bgr, byte> img1 = new Image<Bgr, byte>(ofd.FileName);
        pictureBox1.Image = img1.ToBitmap();
        Image<Gray, Byte> gray1 = img1.Convert<Gray, Byte>().PyrUp().PyrDown();

        CircleF[] circles = gray1.HoughCircles(
        new Gray(150),
        new Gray(100),
        2,
        10,
        0,
        0)[0];
        Image<Bgr, byte> imageCircles = img1.CopyBlank();
        foreach (CircleF circle in circles)
        {
            imageCircles.Draw(circle, new Bgr(Color.Yellow), 5);
        }
        pictureBox4.Image = imageCircles.ToBitmap();
    }
}

我的参数设置正确吗?有什么我没有正确理解的吗? 谢谢!

最佳答案

EmguCV 包装了 OpenCV 的东西,因此您可以通过查看 OpenCV Doku 获得有关如何使用 Emgu 方法的更多信息。 Here是否解释了霍夫变换(可能是参数计数或顺序不同,但在大多数情况下参数名称匹配。在解释点 4(继续应用霍夫圆变换:)您得到了所有参数的解释:

dp = 1: The inverse ratio of resolution
min_dist = src_gray.rows/8: Minimum distance between detected centers
param_1 = 200: Upper threshold for the internal Canny edge detector
param_2 = 100*: Threshold for center detection.
min_radius = 0: Minimum radio to be detected. If unknown, put zero as default.
max_radius = 0: Maximum radius to be detected. If unknown, put zero as default

根据Emgu Doku使用这些值:

cannyThreshold
    Type: TColor
    The higher threshold of the two passed to Canny edge detector (the lower one will be twice smaller).
accumulatorThreshold
    Type: TColor
    Accumulator threshold at the center detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first
dp
    Type: SystemDouble
    Resolution of the accumulator used to detect centers of the circles. For example, if it is 1, the accumulator will have the same resolution as the input image, if it is 2 - accumulator will have twice smaller width and height, etc
minDist
    Type: SystemDouble
    Minimum distance between centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed
minRadius (Optional)
    Type: SystemInt32
    Minimal radius of the circles to search for
maxRadius (Optional)
    Type: SystemInt32
    Maximal radius of the circles to search for

因此请尝试使用更高的 accumulatorThreshold(例如 150 或 180),因为您的圈子非常明显。在大图像上,更高的 dp 也有帮助,减少您的等待时间。

您的 dp 是 10(我认为这意味着检测到的中心之间有 10 个像素)只是根据您的图像大小取一个更大的数字。 OpenCV 示例使用图像高度的八分之一。

minRadius 为 0 应该没问题,因为您的图像只显示大(黄色)圆圈。

最大 Radios 也应该取决于您的图像大小 - 这将删除图像底部的那些非常大的圆圈。

只需尝试将图像高度的 5% 作为 minRadius,将大约 90% 作为 maxRadius - 或者简单地使用 slider 和应用按钮自己尝试

关于opencv - Emgu CV :using HoughCircles detect many nonexistent circles, 等待很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42108139/

相关文章:

android - 在 Android 上将 OpenCV 与 Unity 结合使用

image - 使用OpenCV获取指纹图像的方向图

python-3.x - 使用 OpenCV 为 png 设置白色背景而不是透明度

c# - 在Emgu + OpenCV中处理带有多个子图像的图像的最佳方法?

c# - 如何在 EmguCV C# 中实时刷新网络摄像头的直方图?

opencv - Emgu CV(或 OpenCV)中多边形集的 Voronoi 图

python - HSV 值是否作为 VSH 存储在 numpy 数组中?

python - 在 Swift 中运行 Python

c# - Emgu,.FindContours() 和 CvInvoke.FindContours() 有什么区别

c# - 如何在不改变宽高比的情况下裁剪图像