HoughCircles Doesn't detect circles correctly in OpenCV

Viewed 2603

I am using Visual Studio 2015, OpenCV.3 and EmguCV.3. My code represented below and the result is shown in the picture. I know that the problem is the input values of HoughCircles function, but I don't know which inputs are suitable for this picture. I appreciate any help.

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

Original Image:

enter image description here

Founded Circles:

enter image description here

2 Answers
Related