我试图读取/设置我的网络摄像头的fps,并读取从我的网络摄像头捕获的特定帧的时间戳,这让我有点吃力.特别是当我try 使用vc.get(cv2.CAP_PROP_POS_MSEC)
、vc.get(cv2.CAP_PROP_FPS)
、vc.get(cv2.CAP_PROP_FRAME_COUNT)
时,它们分别返回-1、0、-1.显然,我漏掉了一些东西.有人能帮帮忙吗?代码如下所示:
import os
import time
import cv2
import numpy as np
[...]
# Create a new VideoCapture object
vc = cv2.VideoCapture(0, cv2.CAP_DSHOW)
vc.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
vc.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
# Initialise variables to store current time difference as well as previous time call value
previous = time.time()
delta = 0
n = len(os.listdir("directory"))
# Keep looping
while True:
timem = vc.get(cv2.CAP_PROP_POS_MSEC)
fps = vc.get(cv2.CAP_PROP_FPS)
total_frames = vc.get(cv2.CAP_PROP_FRAME_COUNT)
print(timem, fps, total_frames)
# Get the current time, increase delta and update the previous variable
current = time.time()
delta += current - previous
previous = current
# Check if 3 (or some other value) seconds passed
if delta > 3:
# Operations on image
# Reset the time counter
delta = 0
_, img = vc.read()
[...]
# press esc to exit
if cv2.waitKey(20) == 27:
break
edit:如果我go 掉cv2.CAP_DSHOW
,它可以工作,但我不能使用CAP_PROP_FRAME_WIDTH