背景

这是我的Emgu.CV代码,用于获取图像并绘制其中的圆圈(主要来自Emgu.CV.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);


这是图片:



问题


好,所以我知道ThresholdBinary中的阈值是多少。由于我是从灰度图像中获取二进制图像,因此它是图片中灰度的强度。这在图片中灰度圆的强度为150到185时起作用。我假设对于HoughCircles的第一个参数,这是相同的。

我不知道是什么circleAccumulatorThreshold,累加器分辨率和最小距离(到HoughCircles的第二,第三和第四个args)或应该在其中输入什么值。我显然没有正确的值,因为图片中的圆圈未正确“加粗”。
我的第二个问题是,有没有找到圆形的更好方法?我需要能够在多种类型的光中检测到该圆圈(即圆圈的颜色强度可能较低,例如80或更低),并在图片中获取其尺寸。匹配圆的最佳方法是什么?我是否应该使圆圈为其他颜色,并在原始图像中寻找该颜色?还有其他想法吗?


谢谢

最佳答案

累加器是必须“累加”多少点才能被认为是
圈。数字越高,表示检测到的圆圈越少。
分辨率是如何
封闭点必须位于建议的圆上。基本上
像素的“大小”。
MinDistance是允许圆圈的接近程度
彼此相处。在您的示例中,您非常有3个圈子
彼此靠近。增加最小距离将防止
重叠的圆圈,只画一个。


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

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

10-11 04:08