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?
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: