title: Get the external contour of multiple small contours in OpenCV
body: <p>So I have the following image composed with multiple and small pieces and would like to get its external contour as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/IxxVR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IxxVR.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/vNE74.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vNE74.jpg" alt="enter image description here"></a></p>
  
  <p>I have previously used both <em>Contour approximation</em> and <em>Convex Hull</em> functions to get the approximated external contours but they were just made of 1 single contour, whereas in this case the smaller parts do matter. </p>
  
  <p>The function I've previously used is similar to this one:</p>
  
  <pre><code>canvas = np.zeros(img.shape, np.uint8)
  
  img2gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  kernel = np.ones((5,5),np.float32)/25
  img2gray = cv2.filter2D(img2gray,-1,kernel)
  
  ret,thresh = cv2.threshold(img2gray,120,255,cv2.THRESH_BINARY_INV)
  im2,contours,hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
  
  cnt = contours[0]
  max_area = cv2.contourArea(cnt)
  
  for cont in contours:
      if cv2.contourArea(cont) &gt; max_area:
          cnt = cont
          max_area = cv2.contourArea(cont)
  
  hull = cv2.convexHull(cnt)
  
  cv2.drawContours(canvas, hull, -1, (0, 255, 0), 3)
  </code></pre>
  
  <p>As you can guess, the output is far from the desired one:</p>
  
  <p><a href="https://i.stack.imgur.com/zQahE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zQahE.jpg" alt="enter image description here"></a></p>
  
  <p>Any idea on how to get it closer to the desired one?</p>