2011-08-25 61 views
0

我試圖做一個關於如何使用HoughTransformation類的AForge的實驗。我使用這個類來嘗試計算圖像上的圓圈數量。但我總是得到這個錯誤信息:源圖像的不支持的像素格式。 這裏是我的代碼:AForge Hough變換

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

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()); 
}