[英]How to set time limit in real time video capturing?
我有從相機捕獲視頻的代碼。捕獲的幀附加到列表中。但是如何設置此捕獲的時間限制?。我只想捕獲錄制必須停止后的前兩分鍾。我的代碼是
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()
使用時間包
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.