EmguCV 和 OpenCV 中的 HoughCircles 有什么区别?

eva*_*van 2 c# python opencv emgucv

我正在尝试使用 EmguCV 2.2 和 C# 检测此图像中的圆圈,但没有任何运气。

在此处输入图片说明

将 OpenCV 与 cv2 python 包一起使用,以下代码正确地找到了上图中的 8 个圆圈:

img = cv2.imread('test2.png')   
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, 1, 10, param1=15, param2=10, minRadius=5, maxRadius=5)
Run Code Online (Sandbox Code Playgroud)

为简洁起见,我将省略将圆圈绘制到 img 上的代码,但为了参考输出 - 假设我使用 cv2.circle 用绿色填充每个找到的圆圈,如下所示:

在此处输入图片说明

但是我似乎无法使用 C# 找到那些相同的圈子。

我已经对参数进行了相当多的操作,但是尝试使用以下代码在图像中找不到任何圆圈:

var gray = new Image<Gray, byte>("test2.png");
var circles = gray.HoughCircles(
                accumulatorThreshold: new Gray(16), dp: 1,
                cannyThreshold: new Gray(9),
                minDist: 10, minRadius: 4, maxRadius: 6)[0];
Run Code Online (Sandbox Code Playgroud)

任何使用 C# 找到这 8 个圆圈的帮助将不胜感激!

在此先感谢您的帮助!

Bal*_*i R 5

我使用以下代码查找霍夫圆

Image<Bgr, byte> Img_Result_Bgr = new Image<Bgr, byte>(Img_Source_Gray.Width, Img_Source_Gray.Height);
CvInvoke.cvCvtColor(Img_Source_Gray.Ptr, Img_Result_Bgr.Ptr, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_GRAY2BGR);
Gray cannyThreshold = new Gray(12);
Gray circleAccumulatorThreshold = new Gray(26);
double Resolution = 1.90;
double MinDistance = 10.0;
int MinRadius = 0;
int MaxRadius = 0;

CircleF[] HoughCircles = Img_Source_Gray.Clone().HoughCircles(
                        cannyThreshold,
                        circleAccumulatorThreshold,
                        Resolution, //Resolution of the accumulator used to detect centers of the circles
                        MinDistance, //min distance 
                        MinRadius, //min radius
                        MaxRadius //max radius
                        )[0]; //Get the circles from the first channel
#region draw circles
foreach (CircleF circle in HoughCircles)
    Img_Result_Bgr.Draw(circle, new Bgr(Color.Red), 2);
#endregion

imageBox1.Image = Img_Result_Bgr;
Run Code Online (Sandbox Code Playgroud)

这是程序输出

此外,由于这些圆是分开的,我更喜欢使用最小封闭圆方法来找到这些圆坐标。请参阅此链接

轻松找到这些圆的坐标:

  1. 查找此二进制图像的轮廓。
  2. 循环浏览每个轮廓。
  3. 将轮廓点转换为点集合。
  4. 为该点集合查找 MinEnclosureCircle()。
  5. 精确获取每个圆的坐标。