如何检测铁路的不连续性?

时间:2017-11-20 17:23:01

标签: python opencv3.0

我在学校有一个项目要求我检测铁路上的任何不连续性。这个想法是通过摄像机拍摄铁路视频(它的模型,铁路的宽度只有3厘米),然后一个程序(我必须创建)必须能够检测出任何不连续性铁路。

目前,我创建了一个能够检测水平线的程序(如果需要,可以轻松更改以检测垂直线,具体取决于视频的拍摄方式)。我的想法是计算两条线之间的距离,以便在距离太远时检测不连续性。问题是,我的程序在检测长行时遇到一些困难(它会检测到许多小行)。

有没有人有想法检测所有铁路只有2条大线而不是很多小线? 我试图在互联网上寻找有用的东西,但这个程序是我找到的唯一一个。也许某人已经有东西可以探测到铁路?

提前感谢您的帮助!

以下是我处理的代码:

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) & 0xFF == ord('q'):
               break
    else:
        print "Line not detected"
        #'http://192.168.43.1:8080/'      


camera.release()
cv2.destroyAllWindows()

First example of the results of the code

Second example of the results of the code

0 个答案:

没有答案
相关问题