我正在使用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,那对你来说好吗? –