如何使用OpenCV Python降低USB Webcam 2.0的帧速率 [英] How to decrease frame rate of USB webcam 2.0 using openCV python

查看:154
本文介绍了如何使用OpenCV Python降低USB Webcam 2.0的帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ubuntu 16.04 并使用 USB 2.0网络摄像头.我想 降低帧速率 以某种方式,因为我正在从事的项目需要人脸检测,这确实落后于视频,因此希望降低帧频.

I am working on ubuntu 16.04 and using a USB 2.0 webcam. I want to decrease the frame rate somehow since the project I'm working on requires face detection which really lags the video hence want to decrease the frame rate.

我尝试实现以下代码

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 15)
fps = int(cap.get(5))
print("fps:", fps)

while(cap.isOpened()):

    ret,frame = cap.read()
    if not ret:
        break

    cv2.imshow('frame', frame)

    k = cv2.waitKey(1)
    if k == 27:
        break

我收到以下错误

(python3:24100): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

如果我将上述代码中的帧频设置为30(默认帧频),那么我会得到正确的视频,但是如果更改它,则会出现上述错误.

If i set the frame rate in the above mentioned code to 30 (default frame rate) then i get a proper video, but if I change it I get the above mentioned error.

如何通过代码或什至通过设置手动降低帧速率(如果可以的话)

How can i decrease the frame rate either through code or even manually through settings (if there's a way)

推荐答案

好的,有几种方法可以做到这一点,但我建议您首先检查一下网络摄像头的功能.您可以通过安装:

Okay, there is several ways you can do this but I would suggest first checking the capabilities of the webcam. You can do this by installing:

sudo apt-get install v4l-utils

然后运行:

v4l2-ctl --list-formats-ext

如果未列出所需的帧速率,则可以增加 cv2.waitKey()中的值,并使用 time.time()对其计时,以获取帧速率你想要的.

If the desired frame rate is not listed you can increase the value in cv2.waitKey() and time it with time.time() to get the frame rate you want.

这篇关于如何使用OpenCV Python降低USB Webcam 2.0的帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆