title: Detecting and counting blobs/connected objects with opencv
body: <p>I want to detect and count the objects inside an image that touch while ignoring what could be considered as a single object. I have the basic image, on which i tried applying a <code>cv2.HoughCircles()</code> method to try and identify some circles. I then parsed the returned array and tried using <code>cv2.circle()</code> to draw them on the image.</p>
  <p>However, I seem to always get too many circles returned by <code>cv2.HoughCircles()</code> and couldn't figure out how to only count the objects that are touching.</p>
  <p><a href="https://i.stack.imgur.com/9qkeY.jpg" rel="nofollow noreferrer">This is the image i was working on </a></p>
  <p>My code so far:</p>
  <pre><code>import numpy
  import matplotlib.pyplot as pyp
  import cv2
  
  segmentet = cv2.imread('photo')
  houghCircles = cv2.HoughCircles(segmented, cv2.HOUGH_GRADIENT, 1, 80, param1=450, param2=10, minRadius=30, maxRadius=200)
  houghArray = numpy.uint16(houghCircles)[0,:]
  
  for circle in houghArray:
      cv2.circle(segmented, (circle[0], circle[1]), circle[2], (0, 250, 0), 3)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/wSAGT.jpg" rel="nofollow noreferrer">And this is the image i get, which is quite a far shot from want i really want.</a></p>
  <p>How can i properly identify and count said objects?</p>