Reputation: 1130
I'm trying to detect shapes with a specific color, using openCV. The first thing i'm trying to do, is to detect circles in an image.
I'm able to detect the circles, using houghCircles, with this function call:
HoughCircles(gray, c, CV_HOUGH_GRADIENT, 1.5, gray.rows / 10, 200, 100, 0, 0);
Now i'm trying to detect the circles with the specific color. I'm doing this using the inRange function, which returns a 8-bit, single-channel image.
This function is able to filter only the given color out of the image. I.e. yellow.
But when i pass the returned image in to the houghCircles function, it's returning no circles. There are no compilation errors.
I already tried to change some of the parameters of houghCircles, but i'm not able to detect the circle.
This is an example of the image that inRange is returning: Grayscale image
What parameters do i need to use, to detect the circle in that image?
Thanks in advance,
Peter
Upvotes: 0
Views: 260
Reputation: 630
By doing some playing around with your image, I have found a set of parameters that work.
HoughCircles(shapes, circles, CV_HOUGH_GRADIENT, 1, shapes.rows / 4, 400, 20, 0, 0);
I doubt these are ideal parameters, and I strongly advise you to go and build your own app for changing function parameters - there are plenty of examples of simple slider-based apps in the OpenCV docs which you can use to play around with parameters until you hit upon something that works. This one, for example, is a demo for Hough Circles.
Additionally, you may not be using the best tool for the job. By using contours, you should be able to detect and classify a whole bunch of different shapes, not just circles. This tutorial is very close to what you're trying to do and probably worth a read.
Upvotes: 1