3

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)

Osama
  • 55
  • 4

1 Answers1

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.

Christoffer
  • 483
  • 2
  • 10