title: How to remove Edge Text in image using Opencv
body: <p>I want to remove the text on the edged in the image
  I have used the following code but it does not work it also remove the text in the center</p>
  <p>Input:</p>
  <p><img src="https://i.stack.imgur.com/kShDc.jpg" alt="Input Image " /></p>
  <p>Output:</p>
  <p><img src="https://i.stack.imgur.com/YAS6J.jpg" alt="Output image" /></p>
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  import glob
  import os
  import numpy as np
  def crop_buttom_text(img):
      &quot;&quot;&quot; Remove the text from the bottom edge of img &quot;&quot;&quot;
      gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      #blur = cv2.GaussianBlur(gray, (9,9), 0)  # No need for blurring
      thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
  
      # Create rectangular structuring element and dilate
      kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (30, 1))  # Use horizontal line as kernel - dilate horizontally.
      dilate = cv2.dilate(thresh, kernel, iterations=1)
      #kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (10,10))
      #dilate = cv2.morphologyEx(dilate, cv2.MORPH_OPEN, kernel)    # No need for opening
  
      # Find contours and draw rectangle
      cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]  # [-2] indexing takes return value before last (due to OpenCV compatibility issues).
      #cnts = cnts[0] if len(cnts) == 2 else cnts[1] # [-2] is shorter....
  
      res_img = img.copy()  # Copy img to res_img - in case there is no edges text.
  
      for c in cnts:
          x, y, w, h = cv2.boundingRect(c)
  
          y2 = y + h  # Bottom y coordinate of the bounding rectangle
  
          if (y2 &gt;= img.shape[0]):
              # If the rectangle touches the bottom of the img
              res_img = res_img[0:y-1, :].copy()  # Crop rows from first row to row y-1
  
      return res_img
  def remove_lines(image_path,outdir):
      image = cv2.imread(image_path)
      img1 = crop_buttom_text(image)
      img2 = crop_buttom_text(np.rot90(img1)) # Rotate by 90 degrees and crop.
      img3 = crop_buttom_text(np.rot90(img2)) # Rotate by 90 degrees and crop.
      img4 = crop_buttom_text(np.rot90(img3)) # Rotate by 90 degrees and crop.
  
      output_img = np.rot90(img4)
      cv2.imwrite(os.path.join(outdir,os.path.basename(image_path)), output_img)
      
  for jpgfile in glob.glob(r'/content/Dataset/*'):
      print(jpgfile)
      remove_lines(jpgfile,r'/content/output')
  </code></pre>
  <p>How can i modify the above code to remove the text around the edge</p>