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

3
我正在尝试使用C#的EmguCV 2.2来检测这个图像中的圆,但是没有成功。使用带有cv2 python包的OpenCV,以下代码可以在上面的图像中正确找到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)

为了简洁起见,我将省略绘制圆形图像的代码,但是参考输出结果——假设我使用cv2.circle将每个找到的圆形填充为绿色,如下所示:

enter image description here

然而,我似乎无法在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 个圆的帮助将不胜感激!

提前感谢您的帮助!

1个回答

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;

这里是程序输出

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

要轻松找到这些圆的坐标:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接