I am using HoughCircles to detect a ball in real-time, but running Canny on my gray-scale image stream isn't creating all of the edges as it should. To remedy that, I am splitting the rgb image into it's separate channels, performing Canny on each one, then using bitwise or to merge the edges together. This is working quite well, but if I feed that edge image to HoughCircles, it will perform Canny again on the edge image. Is there a way to prevent this, or to forgo the rgb split Canny detection that I am performing while still catching all of the edges?
2 Answers
Indeed! Canny is executed internally by HoughCircles and there's no way to call cv::HoughCircles()
and prevent it from invoking Canny.
However, if you would like to stick with your current approach, one alternative is to copy the implementation of cv::HoughCircles()
available on OpenCV's source code and modify it to suit your needs. This will allow you to write your own version of cv::HoughCircles()
.
If you follow this path, it's important to realize that the C++ API of OpenCV is built upon the C API. That means that cv::HoughCircles()
is just a wrapper around cvHoughCircles()
, which is implemented at opencv-2.4.7/modules/imgproc/src/hough.cpp
after line 1006.
Take a look at this function (line 1006) and notice the call done to icvHoughCirclesGradient()
at line 1064. This is the function responsible for invoking cvCanny()
, which is done at line 817.
Another approach, if the ball is single-colored, could be implemented by using cv::inRange()
to isolate a specific color, and this will provide a much faster detection. Also, this subject has been extensively discussed on this forum. One very interesting thread is:

- 1
- 1

- 92,053
- 36
- 243
- 426
-
The HoughCircles method inside of OpenCV does perform Canny internally. http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html I'd like to be able to shut that off. The ball I'm looking for isn't a single color, nor do we know the ball ahead of time. I've read the question you're referring to before, but it doesn't answer the question that I've asked here though. – Asher Johnson Nov 25 '13 at 03:48
-
Thanks, that's what I was thinking about doing, but was hoping there would be a way around it. Do you know of any other open source implementations of Hough Circles that are more simple that I can adjust how it works? Some tweaks I want to make to the implementation to speed it up. – Asher Johnson Nov 25 '13 at 15:41
-
By the way, [here's an interesting Java implementation](http://users.ecs.soton.ac.uk/msn/book/new_demo/houghCircles/). Feel free to up vote my answer if it helped you or select it as the official problem solver. By doing these doing you are helping future visitors. – karlphillip Nov 25 '13 at 16:01
For people who are looking for using a custom edge detection with circle detection in Python, you can use OpenCV's Canny edge detection function and pass it to scikit-image's (skimage) hough_circle function (http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.hough_circle).
Skimage's hough_circle function doesn't internally perform Canny edge detection, thus giving you a chance to implement your own. Below is an example:
hough_results = hough_circle(cv2.Canny(IMAGE, LOWER_THRESHOLD, UPPER_THRESHOLD), np.arrange(MIN_RADIUS, MAX_RADIUS,1))

- 254
- 4
- 13