title: Opencv - python - Join line segments from Line Segment Detector (LSD) to form one line
body: <p>I am working on this problem of finding popping crease of the cricket pitch and I have somewhat achieved what I wanted to do that is I can detect vertical line segments using LSD from opencv but what I dont seem to understand is how to join different line segments on the same line to make a complete line.</p>
  
  <p>The code for finding line segments:</p>
  
  <pre><code>import cv2
  import math
  import numpy as np
  
  #Read gray image
  img = cv2.imread("2.jpg",0)
  
  #Create default parametrization LSD
  lsd = cv2.createLineSegmentDetector(0)
  
  #Detect lines in the image
  lines = lsd.detect(img)[0] #Position 0 of the returned tuple are the detected lines
  print(lines[0][0][0])
  
  ver_lines = []
  
  for line in lines:
      angletan = math.degrees(math.atan2((round(line[0][3],2) - round(line[0][1],2)), (round(line[0][2],2) - round(line[0][0],2))))
  
      if(angletan &gt; 85 and angletan &lt; 95):
          ver_lines.append(line)
  
  #Draw detected lines in the image
  drawn_img = lsd.drawSegments(img,np.array(ver_lines))
  
  #Show image
  cv2.imshow("LSD",drawn_img )
  cv2.waitKey(0)
  </code></pre>
  
  <p>Input Image:<a href="https://i.stack.imgur.com/NgdKy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NgdKy.jpg" alt="enter image description here"></a></p>
  
  <p>Detected lines:<a href="https://i.stack.imgur.com/GAaCO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GAaCO.png" alt="enter image description here"></a></p>
  
  <p>what I would like to have:<a href="https://i.stack.imgur.com/WyTyi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WyTyi.png" alt="enter image description here"></a></p>