title: Removing black background/black stray straight lines from a captcha in python
body: <p>I am trying read text from this image] using Python with OpenCV.</p>
  <p><a href="https://i.stack.imgur.com/X3ZQo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X3ZQo.png" alt="enter image description here" /></a></p>
  <p>However, black background in corners if this pic is messing with the text output and is giving wrong text.</p>
  <p>I tried to used Adaptive Gaussian Thresholding in OpenCV using code:</p>
  <pre><code>import cv2 as cv
  import numpy as np
  from matplotlib import pyplot as plt
  img=cv.imread(file_path,0)
  
  img = cv.medianBlur(img,5)
  ret,th1 = cv.threshold(img,127,255,cv.THRESH_BINARY)
  
  th2 =cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C,\
          cv.THRESH_BINARY,11,2)
  
  **th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\
          cv.THRESH_BINARY,11,2)**
  
  titles = ['Original Image', 'Global Thresholding (v = 127)',
          'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
  
  images = [img, th1, th2, th3]
  
  for i in range(4):
      plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')
      plt.title(titles[i])
      plt.xticks([]),plt.yticks([])
  
  plt.show()
  </code></pre>
  <p>The output of this code as AGT_result</p>
  <p><a href="https://i.stack.imgur.com/PWmhW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PWmhW.png" alt="" /></a></p>
  <p>How to extract the words only?</p>