title: Recognizing overlapping objects
body: <p>I am processing an image with <strong>OpenCV</strong> on <strong>Python</strong> and I want to count every objects (worms) on it. Worms are rather light beige whereas the background is black (see picture) so it is rather easy to distinguish them. The problem is that sometimes worms are too close to each other (sometimes they even overlap) and <em>cv.findContours()</em> will draw one big contour instead of two smaller ones (see picture below).</p>
  
  <p>Because I am using <em>cv.foundContours()</em>, I have to first turn the picture into black and white, then blur it (optional) and finally threshold it in order to have white worms in a black background.</p>
  
  <p>I am using the following code :</p>
  
  <pre><code>import cv2 as cv
  img = cv.imread('worms.jpg')
  gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
  blur=cv.GaussianBlur(gray,(5,5),1)
  ret,osu = cv.threshold(blur,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
  imsource,contours,test = cv.findContours(osu,1,1)
  cv.drawContours(img,contours,-1, (0,0,255),2)
  </code></pre>
  
  <p>I tried to erode the thresholded picture but it doesn't work well since the "bond" between two worms is quite big. </p>
  
  <p><img src="https://i.stack.imgur.com/fCoOC.jpg" alt="     Picture Processing      "></p>
  
  <p>Thanks for the help</p>