title: Filled circle detection using CV2 in Python?
body: <p>I am trying to detect all the circles in <a href="https://dl.dropboxusercontent.com/u/113663/hough/P1174020.jpg" rel="nofollow">images like this.</a></p>
  
  <p>I have many different images like this but in all the circles will be black (or almost black) and of the same size (+/- a couple of pixels). I believe there are exactly 2943 circles in each image. These conditions never change. I may not be able to control the sizes of the circles across images (usually ranges between 15-45 pixels in radii - the example image provided above has radii of 20-21 pixels).</p>
  
  <p>I need to be able to detect the exact locations of the centers of these circles as accurately and precisely as possible (if possible, the radii too).</p>
  
  <p>I tried using the <code>cv2.HoughCircles</code> function to do so, but got very inconsistent and unreliable results. Here is the code that I used:</p>
  
  <pre><code>from pylab import *
  import sys, cv2
  
  filename = sys.argv[1];
  img = cv2.imread(filename,0);
  cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR);
  circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,2,15,param1=100,param2=30,minRadius=15,maxRadius=25);
  circles = np.uint16(np.around(circles));
  for i in circles[0,:]:
      cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),1);
      cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3);
  cv2.imwrite('1-%s'%(filename),cimg)
  print "%d circles found."%(len(circles[0]));
  </code></pre>
  
  <p>The result was <a href="https://dl.dropboxusercontent.com/u/113663/hough/1-P1174020.jpg" rel="nofollow">this image</a> and this output: <code>2806 circles found.</code></p>
  
  <p>There are many false circles and many of the true circles have been missed/ignored.</p>
  
  <p>I am starting to believe that the <code>HoughCircle</code> method is not the most optimal way to go if all my circles are identical in a single image, and there might be some better object detection method available.</p>
  
  <p>What do you suggest I use to detect every circle precisely and accurately across thousands of images if I can control the properties of the circles tightly enough?</p>