title: How can I detect a discontinuity on railways?
body: <p>I have a project at school that asks me to detect any discontinuity on railways. The idea is taking a video of railways (it's a model, the witdh of the railways is only 3 cm) thanks to a camera, and then a program (I have to create) has to be able to detect any discontinuity on the railways.</p>
  
  <p>For now, I created a program able to detect horizontal lines (it can be changed easily to detect vertical lines if necessary, depending on how the video is taken). My idea is to calculate the distance between two lines in order to detect a discontinuity if the distance is too high. The problem is, my program has some difficulties to detect long lines (it detects a lot of little lines instead).</p>
  
  <p>Does anyone has an idea to detect all the railways with only 2 big lines instead of a lot of little lines ?
  I tried to look on internet to find something helpful, but this program is the only one I found. Maybe someone already has something to detect railways ?</p>
  
  <p>Thanks in advance for your help !</p>
  
  <p>Here is the code I work on :</p>
  
  <pre><code>import numpy as np
  import cv2
  import math as m
  
  camera = cv2.VideoCapture('mavideo.mp4')
  
  while (camera.isOpened()):
      ret,frame1 = camera.read()
      frame = cv2.resize(frame1,(600,600)) 
  
      edge = cv2.Canny(frame,100,200,apertureSize=3)
  
      minLineLength = 10
      maxLineGap = 15
  
      line = cv2.HoughLinesP(edge,1,np.pi/180,100,minLineLength,maxLineGap)
  
  
      if line is not None:
  
              for (x1,y1,x2,y2) in line[0]:
                  if y2==y1:
                      cv2.line(frame,(x1, y1), (x2, y2), (0,255,0),5)
  
                      if line.any()==True:
                          d = m.sqrt(m.pow((x2-x1),2)+m.pow((y2-y1),2))
                          print d
                          print "Line Detected"
  
              cv2.imshow("line detection",frame)
              cv2.imshow('edge',edge)
  
              if cv2.waitKey(1) &amp; 0xFF == ord('q'):
                 break
      else:
          print "Line not detected"
          #'http://192.168.43.1:8080/'      
  
  
  camera.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0KsWv.png" rel="nofollow noreferrer">First example of the results of the code</a></p>
  
  <p><a href="https://i.stack.imgur.com/EOxAo.png" rel="nofollow noreferrer">Second example of the results of the code</a></p>