How to decrease frame rate of USB webcam 2.0 using openCV python

别来无恙 提交于 2021-01-27 13:20:51

问题


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.

I've tried implementing the following code

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

I get the following error

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

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)


回答1:


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

And run:

v4l2-ctl --list-formats-ext

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.



来源:https://stackoverflow.com/questions/55586506/how-to-decrease-frame-rate-of-usb-webcam-2-0-using-opencv-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!