Click here to Skip to main content
14,330,747 members
Rate this:
Please Sign up or sign in to vote.
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.
Member 14129828 10-Oct-19 1:28am
   
can you tell me what is the command or give me a paper can help me to know how to detect the white color please...if you don't have mind
RedDk 10-Oct-19 13:53pm
   
Sure. There must be something you'll be able to do using a current version of VS and a few downloads from elswhere. Check these out:

https://www.codeproject.com/Articles/1187512/Image-recognition-with-Csharp-and-Emgu-libraries
https://www.codeproject.com/Articles/196168/Contour-Analysis-for-Image-Recognition-in-C
https://www.codeproject.com/Articles/19323/Image-Recognition-with-Neural-Networks

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100