我正在尝试在我的直播视频流中制作HoughLines
。我想检测所有边缘只有45度左右,但输出视频的线条非常小,看起来像是在移动。它们没有固定,也没有覆盖所有相关的边缘。
请参阅以下代码:
import numpy as np
import cv2
cam = cv2.VideoCapture(0)
while (True):
s, img = cam.read()
winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.WINDOW_AUTOSIZE)
edges = cv2.Canny(img, 100, 200)
lines = cv2.HoughLinesP(edges, 1, np.pi / 4, 2, None, 10, 1)
if lines is not None:
for line in lines[0]:
pt1 = (line[0], line[1])
pt2 = (line[2], line[3])
cv2.line(img, pt1, pt2, (0, 0, 255), 3)
cv2.imshow('edges', edges)
cv2.imshow('original', img)
if cv2.waitKey(10) & 0xff == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
答案 0 :(得分:0)
您只使用一组坐标:
for line in lines[0]:
使用这个:
if lines is not None:
for l in lines:
for x1, y1, x2, y2 in l:
cv2.line(img, (x1, y1), (x2, y2), (255, 255, 255), 20, 5)