title: Merge MSER detected objetcs (OpenCV, Python)
body: <p>I am working on this image as source:</p>
  
  <p><a href="https://i.stack.imgur.com/nGxl6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nGxl6.png" alt="src"></a></p>
  
  <p>Applying the next code...</p>
  
  <pre><code>import cv2
  import numpy as np
  
  mser = cv2.MSER_create()
  img = cv2.imread('C:\\Users\\Link\\Desktop\\test2.png')
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  vis = img.copy()
  regions, _ = mser.detectRegions(gray)
  hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
  cv2.polylines(vis, hulls, 1, (0, 255, 0))
  
  mask = np.zeros((img.shape[0], img.shape[1], 1), dtype=np.uint8)
  for contour in hulls:
      cv2.drawContours(mask, [contour], -1, (255, 255, 255), -1)
  
      text_only = cv2.bitwise_and(img, img, mask=mask)
  
  cv2.imshow('img', vis)
  cv2.waitKey(0)
  cv2.imshow('img', mask)
  cv2.waitKey(0)
  cv2.imshow('img', text_only)
  cv2.waitKey(0)
  
  cv2.imwrite('C:\\Users\\Link\\Desktop\\test_o\\1.png', text_only)
  </code></pre>
  
  <p>...I am obtaining this as result (mask):</p>
  
  <p><a href="https://i.stack.imgur.com/6N5VQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6N5VQ.png" alt="o1"></a></p>
  
  <p>The question is this:</p>
  
  <p>how to merge into a single object <code>the number 5</code> in the number series (157661546) as long as it is divided in the mask image ?</p>
  
  <p>Thanks</p>