【问题标题】:What are the differences between HoughCircles in EmguCV and OpenCV?EmguCV 和 OpenCV 中的 HoughCircles 有什么区别?
【发布时间】:2014-08-09 03:23:48
【问题描述】:

我正在尝试使用 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)

为简洁起见,我将省略将圆圈绘制到 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];

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

提前感谢您的帮助!

【问题讨论】:

    标签: c# python opencv emgucv


    【解决方案1】:

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

    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;
    

    这里是Program Output

    此外,由于这些圆是分开的,我更喜欢使用最小封闭圆方法来找到这些圆坐标。 Refer this link.

    轻松找到这些圆的坐标:

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

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 2019-11-24
      相关资源
      最近更新 更多