我正在使用Visual Studio 2015,OpenCV.3和EmguCV.3。 我的代碼如下所示,結果顯示在圖片中。我知道問題是HoughCircles函數的輸入值,但我不知道哪些輸入適合這張圖片。我感謝任何幫助。HoughCircles在OpenCV中未正確檢測到圓圈
Image<Gray, byte> OriginalImage = new Image<Gray, byte>(Openfile.FileName);
Image<Gray, byte> ResizedImage = OriginalImage.Resize(OriginalImage.Width/2, OriginalImage.Height/2, Emgu.CV.CvEnum.Inter.Cubic);
//********** Convert Image to Binary
Image<Gray, byte> smoothImg =
ResizedImage.SmoothGaussian(5);
smoothImg._Erode(5);
smoothImg._Dilate(5);
Image<Gray, byte> BinaryImage =
smoothImg.ThresholdBinary(new Gray(20), new Gray(255));
//********** Find Circles
Image<Rgb, byte> ROIImgScaledCircles = ROIImgScaled.Convert<Rgb, byte>();
CircleF[] circles = smoothImg.HoughCircles(
new Gray(180),//cannyThreshold
new Gray(60),//circleAccumulatorThreshold
2.0, //dp:Resolution of the accumulator used to detect centers of the circles
10.0, //min distance
10, //min radius
128 //max radius
)[0]; //Get the circles from the first channel
foreach (CircleF cir in circles)
{
ROIImgScaledCircles.Draw(cir, new Rgb(235, 20, 30), 1);
}
pbxCircles.Image = ROIImgScaledCircles.ToBitmap();
原始圖像:
成立圓:
你能提供原始圖像嗎?我猜你期望2個圈子? –
@SimonMourier我編輯了問題並添加了原始圖像。其實是的,我期待2個圈子。 –
我使用opencvsharp(這非常接近C++/python樣本),而不是emgucv,那對你來說好嗎? –