我正在尝试在我的实时视频流中制作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()
目前没有回答
相关问题 更多 >
编程相关推荐