Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to detect a small white ball using "HoughCircles", I have code which detects a red ball.
I don't know how to change the color to white, because I don't understand the command " InRange" and how make it detect a very small ball?

What I have tried:

mainImage = new Image<Bgr, byte>("D://222.jpg");
            processedImage = mainImage.InRange(new Bgr(0, 0, 128), new Bgr(47, 47, 255));
            processedImage = processedImage.SmoothGaussian(9);
            CircleF[] circles = processedImage.HoughCircles(new Gray(100), new Gray(50), 2, processedImage.Height / 4, 4, 400).SelectMany(u => u.Select(s => s)).ToArray();
            foreach (var c in circles)
            {
                
                CvInvoke.Circle(mainImage, new Point((int)c.Center.X, (int)c.Center.Y), 3, new MCvScalar(0, 255, 0), -1, Emgu.CV.CvEnum.LineType.AntiAlias, 0);
                mainImage.Draw(c, new Bgr(Color.Red), 3);
            }
            imageBox1.Image = mainImage;
            imageBox2.Image = processedImage;

I dont understand the parameter of
HoughCircles
and the command
InRange(new Bgr(0, 0, 128), new Bgr(47, 47, 255));
Posted
Comments
Richard MacCutchan 9-Oct-19 12:08pm    
You could ask the person who wrote this code.
Richard Deeming 9-Oct-19 13:31pm    
Random guess: Assuming Bgr represents a colour specified in the rather unusual "blue-green-red" order, try changing the parameters to:
mainImage.InRange(new Bgr(208, 208, 208), new Bgr(255, 255, 255));

Beyond that, as Richard said, you'd need to ask the person who wrote the code.
phil.o 9-Oct-19 14:46pm    
This would qualify as a sensible answer. My virtual 5!
Member 14129828 10-Oct-19 1:20am    
thank you for your answer
RedDk 9-Oct-19 15:49pm    
Having read the CHT entry found in wikipedia, it appears that the "guessing" and the "voting", because the object under scrutiny has no known 2D component (ie: circularity) could be/always will be in 3D ... an estimate has to be made. So iteratively and by blurring the coordinate axis' along with the prospective circle perhaps the two distances can be closed down ... until a better certainty is established. In a nutshell: blurring/grayscaling takes a lot of noise out of the bigger picture. A typical circle becomes less ovoid, right?

See "Gaussian Blur" for details.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900