6

After processing an image by converting it to grey scale and then blurring it, I'm trying to apply a Hough Circle Transformation with these parameters:

  • CV_HOUGH_GRADIENT
  • dp = 1
  • min_dist = 1
  • param_1 = 70
  • param_2 = 100
  • min_radius = 0
  • max_radius = 0

Here is one of the many images I've tried: https://i.stack.imgur.com/JGRiM.jpg

But the algorithm fails to recognise the ball even with relaxed parameters.

(When I try it with an image of a circle created in GIMP it works fine)

user1493372
  • 61
  • 1
  • 2

2 Answers2

9

I agree with krzych. I had it working effortlessly with :

cv::Mat img,img2;
std::vector<cv::Vec3f> circles;
img = cv::imread("JGRiM.jpg",1);
cv::bilateralFilter(img, img2, 15, 1000, 1000);
cv::cvtColor(img2, img2,CV_BGR2GRAY);
cv::HoughCircles(img2, circles, CV_HOUGH_GRADIENT, 1,300,50, 10);
cv::circle(img2,cv::Point(circles[0][0],circles[0][1]),circles[0][2],cv::Scalar(126),2);
cv::imshow("test",img2);

cv::waitKey(0);
cv::imwrite("test.jpg",img2);
return 0;

enter image description here

Good luck :)

Quentin Geissmann
  • 2,240
  • 1
  • 21
  • 36
  • Can you explain how to arrived at your numbers in a bit more detail? I'm attempting do something similar and would like to figure out how to calculate the best numbers to fit my solution. Thanks! – jluzwick May 25 '13 at 17:07
  • 4
    minDist = 300(px) so that we find only one circle (a small value would find multiple circle around the ball). minRad =10 so we avoid counting small circles (noise). for the other parameters, I was lucky :p (this image was very robust to changes though) – Quentin Geissmann May 25 '13 at 18:29
  • Thanks! That was very helpful. What about the bilateral filter? I have been trying to find a good explanation of the parameters in more of a layman's speak. Any advice on that? – jluzwick May 25 '13 at 19:45
0

Check Canny output of your images first. From this Canny output it is possible to detect ball with very small param_2 as well as many false circles on image. (I've used for example param_2 = 10, and with specified ball center to eliminate false circles it works)

Try to help Hough Circle Transform. The task is to segment ball from other elements. In your image problem is line, you can try to segment ball using colours for example.

krzych
  • 2,126
  • 7
  • 31
  • 50
  • can you explain your methodology a bit further? (How to do provide the specified ball center). If I had a ball approximately in the middle of the image that took up 60 to 70 percent of the frame. How would I could about determining the best parameters? – jluzwick May 25 '13 at 17:01
  • 2
    You can detect all circles with very low param_2. That will give you many false circles. Then if you know the center approximately. You can do elimination. Simply iterate over all circles and remove this which distance to specified center approximation is bigger than some delta. – krzych May 25 '13 at 21:07
  • Ah, smart! Yes that is actually very helpful. – jluzwick May 25 '13 at 21:09