title: Python Opencv\ Detect and delete a line on an image
body: <p>My personal project is to study how image processing works using Python. I am totally new to the field.
  I have a little problem that has bothered me for several minutes (Actually it's been an hour that I block something so simple though probably in your eyes ...)</p>
  
  <hr>
  
  <h2>Let me explain:</h2>
  
  <hr>
  
  <p>I would like to extract (or rather "delete") this line on my image (I ironed this one in red so that we can see it at best):
  <a href="http://prntscr.com/hhgzhk" rel="nofollow noreferrer">http://prntscr.com/hhgzhk</a></p>
  
  <p>By following this tutorial (<a href="https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_gradients/py_gradients.html#gradients" rel="nofollow noreferrer">https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_gradients/py_gradients.html#gradients</a>) I managed to make the line in question appear more prominently, as shown this image.
  <a href="http://prntscr.com/hhgy72" rel="nofollow noreferrer">http://prntscr.com/hhgy72</a></p>
  
  <p>I would now like to detect the lines in this image using this method: <a href="https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html#py-hough-lines" rel="nofollow noreferrer">https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html#py-hough-lines</a></p>
  
  <p>Once the methods applied to my image, I get the following error:</p>
  
  <pre><code>   for rho,theta in lines[0]:
  TypeError: 'NoneType' object has no attribute '__getitem__'
  </code></pre>
  
  <p>Here is the content of the code (It corresponds totally to the tutorial:')):</p>
  
  <pre><code>import cv2
  import numpy as np
  
  img = cv2.imread('houghlines3.jpg')
  gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  edges = cv2.Canny(gray,50,150,apertureSize = 3)
  
  lines = cv2.HoughLines(edges,1,np.pi/180,200)
  for rho,theta in lines[0]:
      a = np.cos(theta)
      b = np.sin(theta)
      x0 = a*rho
      y0 = b*rho
      x1 = int(x0 + 1000*(-b))
      y1 = int(y0 + 1000*(a))
      x2 = int(x0 - 1000*(-b))
      y2 = int(y0 - 1000*(a))
  
      cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
  
  cv2.imwrite('houghlines4.jpg',img)
  </code></pre>
  
  <p>Once I have analyzed it, I realize that the error probably comes from the fact that the content of the variable "lines" is <code>None</code>.
  Thus, I deduce that he found no lines on my image.</p>
  
  <p>The question I'm asking myself now is how to extract this line in question?</p>
  
  <p>I do not know if a person has an idea.</p>
  
  <p>I realize that I want to do this on a captcha, and so it's not too ethical. Know that this is entirely educational, I do not want to hurt anyone :(</p>
  
  <hr>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>After some advice, I managed to detect the famous line in question :) Here is the line detected after using Canny and modified the parameters:
  <a href="http://prntscr.com/hhmhe4" rel="nofollow noreferrer">http://prntscr.com/hhmhe4</a></p>
  
  <p>Here is the code (It is not very clean at all but it works):</p>
  
  <pre><code>import cv2
  import numpy as np
  from matplotlib import pyplot as plt
  
  img = cv2.imread('la.png',0)
  # gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  edges = cv2.Canny(img,50,150,apertureSize = 3)
  
  lines = cv2.HoughLines(edges,1,np.pi/50,50)
  for rho,theta in lines[0]:
      a = np.cos(theta)
      b = np.sin(theta)
      x0 = a*rho
      y0 = b*rho
      x1 = int(x0 + 1000*(-b))
      y1 = int(y0 + 1000*(a))
      x2 = int(x0 - 1000*(-b))
      y2 = int(y0 - 1000*(a))
  
      cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
  
  cv2.imwrite('555.jpg',img)
  </code></pre>
  
  <p>My mistake was not having changed the right settings. I now understand better how these functions work</p>