使用我的网络摄像头,我想每隔5秒定时拍照,同时将视频流式传输到浏览器。我怎样才能在Python中做到这一点,最好是Flask和Opencv?
答案 0 :(得分:0)
在Windows上,使用pygame可以非常轻松地使用网络摄像头。
E.g。
import time
from VideoCapture import Device
webCam = Device()
name = 1
while(True): # Take pictures forever
webCam.saveSnapshot(name + '.jpg') # Take picture
time.sleep(5) # Wait 5 seconds
name = name+1 # We don't want to write over the same image every time
在Linux上,它是a bit more complicated,但它仍然是相同的原则。
但是,如果您希望这样做没有延迟,这可能会更好:
import time
from VideoCapture import Device
webCam = Device()
name = 1
while(True): #Take pictures forever
webCam.saveSnapshot(name + '.jpg') #Take picture
start = time.time()
while not (time.time() - start > 50):
pass
name = name+1 #We don't want to write over the same image every time