0

I have some doubts about cvHoughCircles parameters. I have an image that has some circles and I want to count them, the count gives me a wrong number of circles.

So I don't know how to choose some function's parameters like:

dp,min_dist,param1,param2,min_radius, max_radius.

I don't know what numbers I use in this parameters. How Can I calculate this?

RivieraKid
  • 5,923
  • 4
  • 38
  • 47
BrunoBC
  • 1
  • 1
  • 1

1 Answers1

1

Choosing the parameters depends on the images you are using. An explanation of the parameters themselves can be found in the reference here

http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html#cv-houghcircles

Using the function with the following parameters

HoughCircles(gray, circles, CV_HOUGH_GRADIENT,2, gray->rows/4, 200, 100, 10, 50);

Will make it search for circles with a dp of 2, a minimum distance between the circles of 1/4 of the image and accumulator values of max 200,100 that determine what to accept as a circle. The 10 and 50 are minimum and maximum radius for the circles to accept.

If you have trouble finding these parameters try to make a test program that attaches these values to sliders so you can see the result on a test image.

Especially param2 is something that is difficult to determine by measuring. Because you know how many circles are in your image you can do a parameter crawl in the following way:

for(int i=0;i<200;i++) {
 cv::HoughCircles(gray, circles, CV_HOUGH_GRADIENT,2, gray->rows/4, 200, i, 10, 50);
 std::cout<<"HoughCircles with param2="<<i<<" gives "<<circles.size()<<" circles"<<endl;
}

I don't know how param1 and 2 are exactly related but you could do the same with a double for loop to find the optimum. The other values need to be measured from the picture. In stead of making a screenshot you can also save this image with the function:

cvSaveImage("image.jpg",gray);

To make sure you are really measuring the exact picture.

diip_thomas
  • 1,531
  • 13
  • 25
  • thank you so much for you helpe!! I´ve put your parameters but the number of circles gives me a wrong result. My image has 8 circles they are located in this way:two parallel lines of o o o o .how can I measure this parameters pixels,centimeters..I catch my image from a webcam and this webcam is fixed. thanks – BrunoBC May 25 '12 at 12:44
  • My parameters are based on an openCV example so will indeed probably not work for your case. You can try to save a snapshot image from your webcam and then measure the dimensions of your circle with a program like Illustrator or count the pixels in MS Paint. Can you post a link to an example image? – diip_thomas May 25 '12 at 14:14
  • Hi Thomas!thanks so much for the tips!!I'm new in image processing..Now I understood how to calculate the radius I suppose that I do the same thing if I want to Know the distance between the circles, I measure using pixels,dont I? So now I need to Know about param1 and param2 how to calculate both. I would like sending my picture for you, but I dont know how to send the picture using this post.thanks again for all. – BrunoBC May 26 '12 at 02:25
  • Yes you indeed have to measure the pixels themselves. The distance between the circles should also be easy to measure. param1 and param2 are more difficult to determine. If you want to post a link to an image you can use imageshack.us or some similar service and post the link here. – diip_thomas May 28 '12 at 12:11
  • The following question also specifically mentions how to find param2: http://stackoverflow.com/questions/9860667/writing-robust-color-and-size-invariant-circle-detection-with-opencv-based-on – diip_thomas May 28 '12 at 12:22
  • Hi Thomas, this is the link http://imageshack.us/photo/my-images/824/circlesc.png/ I need to be corrected about the number of circles.My results are varying...thanks man!!see you! – BrunoBC May 28 '12 at 12:59
  • I updated my answer to include a way to find the optimum values for your problem – diip_thomas May 29 '12 at 11:07
  • Hi Thomas, you have updated your last answer,haven't you? I will read your update..thanks a lot man!!! – BrunoBC May 29 '12 at 12:41