title: Opencv : How to remove rectangle black box without removing any other characters
body: <p>I would like to remove a rectangle black box from the below image.</p>
  
  <p><a href="https://i.stack.imgur.com/BrRd6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BrRd6.png" alt="enter image description here"></a></p>
  
  <p>I do some preprocessing operation to keep the upper top of the image only. My problem with the rectangle in the middle of the image </p>
  
  <p>This is the preprocessing operation I do on this image </p>
  
  <pre><code>gray = cv2.cvtColor(cropped_top, cv2.COLOR_BGR2GRAY)
  
  
  
  
  binary = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 15, 2)
  
  
  binary = cv2.fastNlMeansDenoising(binary, None, 65, 5, 21)
  
  
  ret, thresh1 = cv2.threshold(binary, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  
  k = np.ones((4,4))
  binary = cv2.morphologyEx(thresh1, cv2.MORPH_CLOSE, k)
  </code></pre>
  
  <p>This is the output till now<br></p>
  
  <p><a href="https://i.stack.imgur.com/faNJD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/faNJD.png" alt="enter image description here"></a></p>
  
  <p>Here it appears 3 lines connected together. I have used <code>cv2.findContours</code>. But till now I failed to remove this rectangle. I know I am doing something wrong regarding contours.</p>
  
  <p>Here is the code I used for detecting contours</p>
  
  <pre><code>_,binary = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY)
  
  
  # find external contours of all shapes
  _,contours,_ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  
  # create a mask for floodfill function, see documentation
  h,w= image.shape
  mask = np.zeros((h+2,w+2), np.uint8)
  
  # determine which contour belongs to a square or rectangle
  for cnt in contours:
      poly = cv2.approxPolyDP(cnt, 0.05*cv2.arcLength(cnt,True),True)
      if len(poly) == 4:
          # if the contour has 4 vertices then floodfill that contour with black color
          cnt = np.vstack(cnt).squeeze()
          _,binary,_,_ = cv2.floodFill(binary, mask, tuple(cnt[0]), 0)
  </code></pre>
  
  <p>how I can successfully remove this black rectangle without distorting letter <strong>Q</strong></p>