实际上,我对使用Computer Vision并不感兴趣。不好意思。
我想检测电车车道的边缘。通常,该代码运行良好,但有时甚至无法画一条线。我不知道为什么。
cropped_Image 函数只是裁剪当前帧的多边形区域。
display_lines 函数绘制角度的绝对值在30到90之间的线。它使用cv2.line绘制线。
代码如下:
_,frame = cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY) # convert image to gray to be one layer
blur = cv2.GaussianBlur(gray,(1,1),0) # to reduce noise in gray scale image
canny = cv2.Canny(blur,150,200,apertureSize=3)
cropped_image = region_of_interest(canny) # simply,it crops bottom of image
lines = cv2.HoughLinesP(cropped_image,1,np.pi / 180,100,np.array([]),minLineLength=5,maxLineGap=5)
hough_bundler = HoughBundler()
lines_merged = hough_bundler.process_lines(lines,cropped_image)
line_image = display_lines(frame,lines_merged)
combo_image = cv2.addWeighted(frame,0.8,line_image,1)
cv2.imshow(‘test’,combo_image)
要查看它:HoughBundler
预期:expected img
Canny:canny img of wrong result
结果:wrong result