【发布时间】:2015-08-18 08:49:51
【问题描述】:
恐怕我遇到了一些超出我新手能力范围的事情。问题的快速总结:我正在尝试在实验期间(使用 OpenSesame)从使用 OpenCV python 模块的网络摄像头捕获实时视频流。我可以让它工作,但我的问题是代码会弹出一个新窗口以显示它正在录制的实时流。如何更改此代码以不显示实时窗口但仍然能够按“q”关闭实时流?
import numpy as np
import cv2
subject = str(self.get('subject_nr'))
cap = cv2.VideoCapture(0)
w=int(cap.get(cv2.CAP_PROP_FRAME_WIDTH ))
h=int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT ))
#Define the codec and create VideoWriter object
#fourcc = cv2.VideoWriter_fourcc(*'DIVX')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('path\to\output'+ subject + '.avi', -1, 20.0, (w,h))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
#Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
【问题讨论】:
-
你可以尝试评论
cv2.imshow('frame',frame)并尝试if( (cv.waitKey(1) & 0xFF == ord('q') ) break; -
啊,谢谢你的回复!我们越来越近了!代码运行并记录,但我仍然无法使用按键释放作业。
-
您可以在控制台激活的情况下尝试击键吗?
-
不幸的是,控制台仍处于活动状态。它只是冻结了,我必须退出才能停止脚本。