title: How to remove Vertical Lines in image opencv Python
body: <p>I wanted to remove both horizontal and vertical lines the following code works well to remove horizontal lines but in this</p>
  <p><img src="https://i.stack.imgur.com/WYrz4.jpg" alt="Original Image" /></p>
  <p>Here is the output image where the horizontal line is removed</p>
  <p><img src="https://i.stack.imgur.com/cMeE0.jpg" alt="Horizontal line Removed" /></p>
  <p>Here is the code attached please can you tell me how can I remove the vertical lines</p>
  <pre><code>import cv2
  import matplotlib.pyplot as plt
  import glob
  import os
  def remove_lines(image_path,outdir):
      image = cv2.imread(image_path)
      result = image.copy()
      gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
      thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
  
      # Remove horizontal lines
      horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (50,1))
      remove_horizontal = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
      
      cnts = cv2.findContours(remove_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
      cnts = cnts[0] if len(cnts) == 2 else cnts[1]
      for c in cnts:
          cv2.drawContours(result, [c], -1, (255,255,255), 5)
  
  
      # Remove vertical lines
      vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,50))
      remove_vertical = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
      #remove_vertical =cv2.dilate(remove_vertical , vertical_kernel, iterations=2)
      cnts = cv2.findContours(remove_vertical, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
      cnts = cnts[0] if len(cnts) == 2 else cnts[1]
      for c in cnts:
          cv2.drawContours(result, [c], -1, (255,255,255), 5)
  
      cv2.imwrite(os.path.join(outdir,os.path.basename(image_path)), result)
      plt.imshow(result)
  for jpgfile in glob.glob(r'C:\custom\TableDetectionWork\images/*'):
      print(jpgfile)
      remove_lines(jpgfile,r'C:\custom\TableDetectionWork\output/')
  </code></pre>