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

发布于 2024-10-29 02:16:38 字数 1814 浏览 8 评论 0原文

背景

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

//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. 我的第二个问题是,有没有更好的方法来找到圆?我需要能够在多种类型的光中检测到这个圆圈(即圆圈颜色强度可能较低,如 80 或更低)并在图片中获取其尺寸。匹配圆圈的最佳方式是什么?我应该将圆圈设为另一种颜色并在原始图像中查找该颜色吗?还有其他想法吗?

谢谢

Background

Here is my Emgu.CV code for getting an image and drawing the circles found in it (mostly code from the ShapeDetection project in Emgu.CV.Examples solution that came with the EmguCV download):

//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);

Here is the image:

Image of circles

The Questions

  1. OK, so I know what the threshold in ThresholdBinary is. Since I am getting the binary image from the gray-scale image it is the intensity of the gray in the picture. This works as the intensity of the gray-scale circle in the pic is 150 to 185. I assume this is the same for the first argument to HoughCircles.

    What I don't know is what circleAccumulatorThreshold, Resolution of the accumulator, and min distance (2nd, 3rd, and 4th args to HoughCircles) are or what values should go there. I obviously do not have the correct values because the circle in the pic is not 'houghed' correctly.

  2. My second question is, is there a better way to find the circle? I need to be able to detect this circle in many types of light (i.e. the circle color intensity may be low, like 80 or lower) and to get its dimensions in the pic. What is the best way to match a circle? Should I make the circle another color and look in the original image for that color? Any other ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぇ气 2024-11-05 02:16:38
  • 累加器是必须“累积”多少点才能被视为
    圆圈。数字越大意味着检测到的圆圈越少。
  • 分辨率是怎样的
    关闭点必须位于建议的圆处。基本上是
    像素的“大小”。
  • MinDistance 是圆允许的距离
    彼此。在你的例子中,你有 3 个圆圈,都非常
    彼此接近。增加最小距离可以防止
    重叠的圆圈,而只画一个。

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

  • accumulator is how many points must 'accumulate' to be considered a
    circle. Higher numbers mean less circles detected.
  • Resolution is how
    close the point has to be to the proposed circle. Basically the
    'size' of the pixel.
  • MinDistance is how close the circles are allowed
    to be to each other. In your example you've got 3 circles all very
    close to each other. Increasing minimum distance would prevent the
    overlapping circles and instead just draw one.

As for your answer to number two, blur the image, convert to greyscale, then threshold to eliminate lighting differences is the usual solution

平生欢 2024-11-05 02:16:38

虽然这个问题已经“很久”了,但我想提出问题 2 的答案,以造福那些可能遇到类似问题的人。

您可以做的是:

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

While this question is a "lot" old, I'd like to propose an answer to question #2 for the benefit of those who might come across similar problem.

What you can do is:

  1. Threshold the image to remove the background,
  2. Detect objects in the image,
  3. Calculate the circularity of the circle (http://en.wikipedia.org/wiki/Shape_factor_(image_analysis_and_microscopy)), it should be 1 if it is a circle. using the method FindContours (in emgucv) provides all information that you need to calculate for the area and the perimeter of a circle. You can then use these information to get the dimension of your detected circle.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文