AForge霍夫变换

时间:2011-08-25 03:10:13

标签: geometry detect

我正在尝试如何使用HoughTransformation类的AForge进行实验。我正在使用这个类来尝试计算图像上的圆圈数。但我总是收到此错误消息:源图像的不支持的像素格式。 这是我的代码:

private void CountCircles(Bitmap sourceImage)
{
    HoughCircleTransformation circleTransform = new HoughCircleTransformation(15);
    circleTransform.ProcessImage(sourceImage);
    Bitmap houghCircleImage = circleTransform.ToBitmap();
    int numCircles = circleTransform.CirclesCount;
    MessageBox.Show("Number of circles found : "+numCircles.ToString());
}

1 个答案:

答案 0 :(得分:2)

HoughCircleTransformation需要二进制位图。

private void CountCircles(Bitmap sourceImage)
{
    var filter = new FiltersSequence(new IFilter[]
    {
      Grayscale.CommonAlgorithms.BT709,                                                     
      new Threshold(0x40)
    });
    var binaryImage = filter.Apply(bitmap);
    HoughCircleTransformation circleTransform = new HoughCircleTransformation(15);
    circleTransform.ProcessImage(binaryImage);
    Bitmap houghCircleImage = circleTransform.ToBitmap();
    int numCircles = circleTransform.CirclesCount;
    MessageBox.Show("Number of circles found : "+numCircles.ToString());
}