Reputation: 9003
Background
Here is my Emgu.CV code for getting an image and drawing the circles found in it (mostly code from the ShapeDetection project in Emgu.CV.Examples solution that came with the EmguCV download):
//Load the image from file
Image<Bgr, Byte> img = new Image<Bgr, byte>(myImageFile);
//Get and sharpen gray image (don't remember where I found this code; prob here on SO)
Image<Gray, Byte> graySoft = img.Convert<Gray, Byte>().PyrDown().PyrUp();
Image<Gray, Byte> gray = graySoft.SmoothGaussian(3);
gray = gray.AddWeighted(graySoft, 1.5, -0.5, 0);
Image<Gray, Byte> bin = gray.ThresholdBinary(new Gray(149), new Gray(255));
Gray cannyThreshold = new Gray(149);
Gray cannyThresholdLinking = new Gray(149);
Gray circleAccumulatorThreshold = new Gray(1000);
Image<Gray, Byte> cannyEdges = bin.Canny(cannyThreshold, cannyThresholdLinking);
//Circles
CircleF[] circles = cannyEdges.HoughCircles(
cannyThreshold,
circleAccumulatorThreshold,
4.0, //Resolution of the accumulator used to detect centers of the circles
15.0, //min distance
5, //min radius
0 //max radius
)[0]; //Get the circles from the first channel
//draw circles (on original image)
foreach (CircleF circle in circles)
img.Draw(circle, new Bgr(Color.Brown), 2);
Here is the image:
The Questions
OK, so I know what the threshold in ThresholdBinary
is. Since I am getting the binary image from the gray-scale image it is the intensity of the gray in the picture. This works as the intensity of the gray-scale circle in the pic is 150 to 185. I assume this is the same for the first argument to HoughCircles
.
What I don't know is what circleAccumulatorThreshold, Resolution of the accumulator, and min distance (2nd, 3rd, and 4th args to HoughCircles
) are or what values should go there. I obviously do not have the correct values because the circle in the pic is not 'houghed' correctly.
My second question is, is there a better way to find the circle? I need to be able to detect this circle in many types of light (i.e. the circle color intensity may be low, like 80 or lower) and to get its dimensions in the pic. What is the best way to match a circle? Should I make the circle another color and look in the original image for that color? Any other ideas?
Thanks
Upvotes: 1
Views: 18143
Reputation: 6615
As for your answer to number two, blur the image, convert to greyscale, then threshold to eliminate lighting differences is the usual solution
Upvotes: 3
Reputation: 696
While this question is a "lot" old, I'd like to propose an answer to question #2 for the benefit of those who might come across similar problem.
What you can do is:
Upvotes: 1