2016-09-22 4 views
2

私はカメラからビデオをキャプチャするコードを持っています。キャプチャされたフレームはリストに追加されます。しかし、このキャプチャに時間制限を設定する方法は??録画を停止しなければならない最初の2分をキャプチャしたいだけです。リアルタイムビデオキャプチャで時間制限を設定するにはどうすればよいですか?

import cv2 
import numpy 

#creating video capture object 
capture=cv2.VideoCapture(0) 

#Set the resolution of capturing to 640W*480H 
capture.set(3,640) 
capture.set(4,480) 
frame_set=[] 
while(True): 
    # Capture frame-by-frame 
    ret, frame = capture.read() 

    # Converting to Gray Scale 
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
    frame_set.append(gray) 
    # Display the resulting frame 
    cv2.imshow('frame',gray) 
    if cv2.waitKey(1) & 0xFF == ord('q'): 
     break 

# When everything done, release the capture 
capture.release() 
cv2.destroyAllWindows() 

答えて

1

使用時間パッケージ

import cv2 
import numpy 
import time 
capture=cv2.VideoCapture(0) 
capture.set(3,640) 
capture.set(4,480) 
frame_set=[] 
start_time=time.time() 
while(True): 
    ret, frame = capture.read() 
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
    frame_set.append(gray) 
    cv2.imshow('frame',gray) 
    if cv2.waitKey(1) & 0xFF == ord('q'): 
     break 
    end_time=time.time() 
    elapsed = end_time - start_time 
    if elapsed > 120: 
     break 
capture.release() 
cv2.destroyAllWindows() 
+0

はどうもありがとうございました – user6745741

関連する問題