You need to move this line up, outside your acquisition loop:

 cap = cv2.VideoCapture(0)

It does a one-time only initialisation.

Answer from Mark Setchell on Stack Overflow
🌐
OpenCV
forum.opencv.org › t › opencv-camera-low-fps › 567
OpenCV Camera Low FPS - OpenCV
December 28, 2020 - Hello, I was using OpenCV 4.5.1 to measure the FPS of my camera and I found the actual FPS measured is way below my expectation. The code I used for measurement is from How to find frame rate or frames per second (fps) in OpenCV ( Python / C++ ) ? | Learn OpenCV #include "opencv2/opencv.hpp" #include using namespace cv; using namespace std; int main(int argc, char** argv) { // Start default camera VideoCapture video(0); // With webcam get(CV_CAP_PROP_FPS) does not work....
Discussions

Increase Camera FPS OpenCV python
Hello intelligent people of FRC community! My team is trying to increase the camera fps using built in opencv python functions. The cameras should be able to get 60fps, but we are currently getting only 10fps sadly. This is what we’ve tried so far: while True: cap = cv.VideoCapture(path) ... More on chiefdelphi.com
🌐 chiefdelphi.com
1
0
February 14, 2024
opencv with the camera framerate 120 FPS
I have a camera, its frame rate can be set 120 FPS, and its resolution is 640*480, but my process only get 60 FPS. How can I run my process with 120 FPS to get every frame of the camera. This is my process: #include "opencv2/opencv.hpp" ... More on github.com
🌐 github.com
6
March 18, 2020
IMX298 low FPS with OpenCV
Hi! I need to capture video from a camera in a resolution of 1920x1080 with the highest possible frame rate, and then work with the resulting image in opencv. Using arducamstill I get the maximum possible 60 FPS, however when using capture2opencv the frame rate is about 10 FPS. More on forum.arducam.com
🌐 forum.arducam.com
0
0
November 8, 2021
python - low fps by using cv2.VideoCapture - Stack Overflow
I have low FPB ~5, I have checked this code on different cameras logitech c270 and logitech 9000, same situation. I completed all the tips about turn off right light etc. import urllib.request as More on stackoverflow.com
🌐 stackoverflow.com
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 148835 › videocapture-captures-at-low-fps
VideoCapture captures at low fps - OpenCV Q&A Forum
May 16, 2017 - Hello I have a camera that captures video (according to the specifications) at a resolution of 640x480 at 120fps. I use the script below to check the speed I can capture frames with OpenCV on Python, but unfortunately I can't capture at the same speed, not even close. import cv2 from time import time cap = cv2.VideoCapture(2) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) start = time() for i in range(120): _, frame = cap.read() end = time() print("FPS: {}".format(120/(end-start))) cap.release() By settingCAP_PROP_FRAME_WIDTH and CAP_PROP_FRAME_HEIGHT properties I get a difference of +3 fps.
🌐
Chief Delphi
chiefdelphi.com › technical
Increase Camera FPS OpenCV python - Technical - Chief Delphi
February 14, 2024 - Hello intelligent people of FRC community! My team is trying to increase the camera fps using built in opencv python functions. The cameras should be able to get 60fps, but we are currently getting only 10fps sadly. This is what we’ve tried so far: while True: cap = cv.VideoCapture(path) cap:cv.VideoCapture cap.set(cv.CAP_PROP_FRAME_WIDTH, 1280) cap.set(cv.CAP_PROP_FRAME_HEIGHT, 720) cap.set(cv.CAP_PROP_FPS, 30) cap.set(cv.CAP_PROP_FOURCC, ...
🌐
GitHub
github.com › opencv › opencv › issues › 16844
opencv with the camera framerate 120 FPS · Issue #16844 · opencv/opencv
March 18, 2020 - question (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org ... I have a camera, its frame rate can be set 120 FPS, and its resolution is 640*480, but my process only get 60 FPS.
Author: opencv
🌐
Arducam Camera Support
forum.arducam.com › t › imx298-low-fps-with-opencv › 1863
IMX298 low FPS with OpenCV - Raspberry Pi Cameras / mipi-camera-modules - Arducam Camera Support Forum
November 8, 2021 - Hi! I need to capture video from a camera in a resolution of 1920x1080 with the highest possible frame rate, and then work with the resulting image in opencv. Using arducamstill I get the maximum possible 60 FPS, however when using capture2opencv the frame rate is about 10 FPS.
🌐
PyImageSearch
pyimagesearch.com › home › blog › increasing webcam fps with python and opencv
Increasing webcam FPS with Python and OpenCV - PyImageSearch
February 20, 2023 - The same notion applies to computer vision and reading frames from a camera — we can improve our FPS simply by creating a new thread that does nothing but poll the camera for new frames while our main thread handles processing the current frame.
Find elsewhere
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson & embedded systems › jetson nano
Jetson nano - opencv webcam low fps - Jetson Nano - NVIDIA Developer Forums
December 18, 2021 - Hi, my aim is to apply some cuda kernels on an image coming from my usb webcam and to show the result. The problem is that I need to do that using images that are full HD. Actually what I am try to do is to get some decent FPS with a base application using opencv, something like while 1: capture >> frame imshow(frame) Doing something like this I obtain around 15 fps.
🌐
GitHub
github.com › opencv › opencv › issues › 26250
Windows get camera cv2.CAP_PROP_FPS incorrect value for low fps. · Issue #26250 · opencv/opencv
October 4, 2024 - System Information Self built Opencv 4.10 for windows with python. Detailed description OpenCV for Windows reports incorrect FPS if Camera was read before and low FPS was set. Steps to reproduce from datetime import datetime,timedelta im...
🌐
Arducam Camera Support
forum.arducam.com › raspberry pi cameras › mipi-camera-modules
OV2311 low fps with opencv - mipi-camera-modules - Arducam Camera Support Forum
May 1, 2020 - Hello, I want to use the OV2311 camera for a tracking project in python with opencv. But I am running into problems getting the expected framerate (Something close to 60 fps). Using auto-exposure (which I prefer to manual) I get around 7 fps. Using manual exposure I get around 12 fps for an ...
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Low framerate on Raspberry PI 4 + PiCamera + Python + OpenCv - Raspberry Pi Forums
Hello For all those who are experiencing problems with low FPS on the Raspberry PI using OpenCv and Python use this script (author CarlosGS). I got very good results, but it will only work with the PI Camera. The python script uses the raspibian native raspividYUV command and obtains the gray scale image with high FPS.
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson & embedded systems › jetson nano
OpenCV with Jetson Nano Slow Webcam frame rate - Jetson Nano - NVIDIA Developer Forums
August 25, 2021 - Hi I used pre-installed opencv on jetson nano with python to read my webcam. It was smooth and with high frame rate. This week, I decided to install OpenCV from source to use CUDA and to be able to use OpenCV in C++. After installing new OpenCV, I ran same python code to test the OpenCV but the frame rate dropped a lot and showed stuttering streaming from webcam.
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 209635 › how-can-i-control-webcam-fps
how can i control webcam fps - OpenCV Q&A Forum
February 28, 2019 - No, it's the contrary: you can use set on CAP_PROP_FPSonly on cameras. Video files have fixed FPS. Anyway, it's better to set the FPS value; timed capture causes lot of problems (for lower framerates jitter, and you cannot increase the framerate)
🌐
Stack Exchange
raspberrypi.stackexchange.com › questions › 143974 › very-low-fps-when-using-opencv
raspicam - Very low fps when using Opencv - Raspberry Pi Stack Exchange
August 7, 2023 - Relatively recently I started writing a project in which faces are detected through raspicam in python using opencv, but the result disappoints me, I get literally 5 fps, but if you remove face detection, then the fps becomes 30 fps, that is, the problem is specifically in the cascades apparently. Sorry for such a translation, I do not communicate in English and use a translator. I'm using raspberry pi 3b. Here is the code I am using: import io import picamera import cv2 import numpy as np stream = io.BytesIO() cv2.namedWindow("Camera Feed") face_cascade =cv2.CascadeClassifier('/home/pi/haarca
🌐
Stack Overflow
stackoverflow.com › questions › 50483948 › opencv-same-capture-code-gives-low-fps-on-a-high-end-laptop-and-high-fps-on-a-t
c++ - Opencv: same capture code gives low FPS on a high-end laptop and high FPS on a TX1 - Stack Overflow
May 23, 2018 - ... I dropped this problem out ... on the lights to find the answer! It turns out that my camera automatically lowers its FPS when in poor light condition....
Top answer
1 of 6
47

Setting a frame rate doesn't always work like you expect. It depends on two things:

  1. What your camera is capable of outputting.
  2. Whether the current capture backend you're using supports changing frame rates.

So point (1). Your camera will have a list of formats which it is capable of delivering to a capture device (e.g. your computer). This might be 1920x1080 @ 30 fps or 1920x1080 @ 60 fps and it also specifies a pixel format. The vast majority of consumer cameras do not let you change their frame rates with any more granularity than that. And most capture libraries will refuse to change to a capture format that the camera isn't advertising.

Even machine vision cameras, which allow you much more control, typically only offer a selection of frame rates (e.g. 1, 2, 5, 10, 15, 25, 30, etc). If you want a non-supported frame rate at a hardware level, usually the only way to do it is to use hardware triggering.

And point (2). When you use cv.VideoCapture you're really calling a platform-specific library like DirectShow or V4L2. We call this a backend. You can specify exactly which backend is in use by using something like:

cv2.VideoCapture(0 + cv2.CAP_DSHOW)

There are lots of CAP_X's defined, but only some will apply to your platform (e.g CAP_V4L2 is for Linux only). On Windows, forcing the system to use DirectShow is a pretty good bet. However as above, if your camera only reports it can output 30fps and 60fps, requesting 10fps will be meaningless. Worse, a lot of settings simply report True in OpenCV when they're not actually implemented. You've seen that most of the time reading parameters will give you sensible results though, however if the parameter isn't implemented (e.g exposure is a common one that isn't) then you might get nonsense.

You're better off waiting for a period of time and then reading the last image.

Be careful with this strategy. Don't do this:

while capturing:
    res, image = cap.read()
    time.sleep(1)

you need to make sure you're continually purging the camera's frame buffer otherwise you will start to see lag in your videos. Something like the following should work:

frame_rate = 10
prev = 0

while capturing:

    time_elapsed = time.time() - prev
    res, image = cap.read()

    if time_elapsed > 1./frame_rate:
        prev = time.time()

        # Do something with your image here.
        process_image()

For an application like a hand detector, what works well is to have a thread capturing images and the detector running in another thread (which also controls the GUI). Your detector pulls the last image captured, runs and display the results (you may need to lock access to the image buffer while you're reading/writing it). That way your bottleneck is the detector, not the performance of the camera.

2 of 6
7

I could not set the FPS for my camera so I manage to limit the FPS based on time so that only 1 frame per second made it into the rest of my code. It is not exact, but I do not need exact, just a limiter instead of 30fps. HTH

import time

fpsLimit = 1 # throttle limit
startTime = time.time()
cv = cv2.VideoCapture(0)
While True:
    frame = cv.read
    nowTime = time.time()
    if (int(nowTime - startTime)) > fpsLimit:
        # do other cv2 stuff....
        startTime = time.time() # reset time