title: Python OpenCV detect circles from black and white mask
body: <p>I have created a black and white mask using various OpenCV filters. There are four circles that are clearly visible <img src="https://i.stack.imgur.com/AJNjo.png" alt="black and white mask"></p>
  
  <p>I am trying to outline these circles using HoughCircles, but it gives many false positives and generally bad results:</p>
  
  <p><code>circles = cv2.HoughCircles(combined, cv.CV_HOUGH_GRADIENT, 1, 300, np.array([]), 10, 30, 60, 300)</code></p>
  
  <p><img src="https://i.stack.imgur.com/jHHVD.png" alt="circle outlines"></p>
  
  <p>How can I properly detect the circular shapes in the black and white image?</p>
  
  <p>Here is runnable code that can be used with the black and white image:</p>
  
  <pre><code>import numpy as np
  import cv2
  import cv
  
  image = cv2.imread("image.png")
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
  circles = cv2.HoughCircles(gray, cv.CV_HOUGH_GRADIENT, 1, 300, np.array([]), 10, 30, 60, 300)
  if circles is not None:
    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        cv2.circle(image, (i[0], i[1]), i[2], (0, 255, 0), 1)
        cv2.circle(image, (i[0], i[1]), 2, (0, 0, 255), 3)
  
  cv2.imshow("thing", image)
  
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>