2016-07-02 243 views

回答

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 
+0

使用time.sleep問題是它停止流式傳輸。我想要流媒體和快照。我期待threading.Timer,但我很困惑 – Mostafa

+0

你可以這樣做:'start = time.time()while not(time.time() - start> 5):pass'參見上面,我編輯了我的答案 –

+0

If這回答了你的問題,請標記我的答案是正確的。但是,如果您仍需要澄清,請在評論中註明。 –