• Here is a very simple way to print your program's frame rate at each frame (no counter needed) :

    import time
    
    while True:
        start_time = time.time() # start time of the loop
    
        ########################
        # your fancy code here #
        ########################
    
        print("FPS: ", 1.0 / (time.time() - start_time)) # FPS = 1 / time to process loop
    
  • If you want the average frame rate over x seconds, you can do like so (counter needed) :

    import time
    
    start_time = time.time()
    x = 1 # displays the frame rate every 1 second
    counter = 0
    while True:
    
        ########################
        # your fancy code here #
        ########################
    
        counter+=1
        if (time.time() - start_time) > x :
            print("FPS: ", counter / (time.time() - start_time))
            counter = 0
            start_time = time.time()
    

Hope it helps!

Answer from Elouarn Laine on Stack Overflow
🌐
LearnOpenCV
learnopencv.com › home › find frame rate (frames per second-fps) in opencv (python/c++)
Find frame rate (frames per second-fps) in OpenCV (Python/C++)
July 31, 2026 - The documentation says that get(CAP_PROP_FPS) gives the frames per second. Now that is true for video files, but not for webcams. For webcams and many other connected cameras, you have to calculate the frames per second manually.
🌐
GeeksforGeeks
geeksforgeeks.org › python-displaying-real-time-fps-at-which-webcam-video-file-is-processed-using-opencv
Python - Displaying real time FPS at which webcam/video file is processed using OpenCV - GeeksforGeeks
January 4, 2023 - import numpy as np import cv2 import time # creating the videocapture object # and reading from the input file # Change it to 0 if reading from webcam cap = cv2.VideoCapture('vid.mp4') # used to record the time when we processed last frame prev_frame_time = 0 # used to record the time at which we processed current frame new_frame_time = 0 # Reading the video file until finished while(cap.isOpened()): # Capture frame-by-frame ret, frame = cap.read() # if video finished or no Video Input if not ret: break # Our operations on the frame come here gray = frame # resizing the frame size according to
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-find-the-frames-per-second-of-a-video-Python-OpenCV.php
How to Find the Frames Per Second in a Video in Python using OpenCV
In order to make a video human watchable, we need to introduce time delay to slow it down. To know the time delay needed, we calculate it based off the FPS, which can be found according to the formula, T= 1/f. That's why all of this is important. And this is how we can find the frames per second ...
🌐
YouTube
youtube.com › zubayer hossain
Calculate FPS from live video. Python OpenCV - YouTube
In this video, I show you a simple script to calculate the frames per second of your video feed. Also, I show you how to connect with your webcam if it is a ...
Published: September 2, 2021
Views: 6K
🌐
YouTube
youtube.com › watch
Calculate FPS and Average FPS from live video using OpenCV python - YouTube
This is a shorter video of mine on how to calculate the fps of a video using math and opencv and later show it on the frame.
Published: January 4, 2023
🌐
O'Reilly
oreilly.com › library › view › mastering-opencv-4 › 9781789344912 › 16bc0972-4698-414e-85a1-b2c85bcbb464.xhtml
Calculating frames per second - Mastering OpenCV 4 with Python [Book]
Calculating frames per second In the Reading camera frame and video files section, we saw how we can get some properties from the cv2.VideoCapture object. fps is an important... - Selection from Mastering OpenCV 4 with Python [Book]
Find elsewhere
🌐
YouTube
youtube.com › codehut
how to calculate fps in python - YouTube
Instantly Download or Run the code at https://codegive.com sure, here's an informative tutorial on how to calculate frames per second (fps) in python using ...
Published: March 5, 2024
Views: 33
🌐
Top Tech Boy
toptechboy.com › calculating-frames-per-second-fps-in-opencv-and-overlay-on-frame
Calculating Frames Per Second (FPS) In OpenCV and Overlay on Frame | Technology Tutorials
January 26, 2023 - In this lesson we show how to instrument our code to calculate the Frames Per Second (FPS) we are achieving with our camera and OpenCV. We show how to display the FPS as an overlay on our video frame. Python · Accessibility Statement ·
🌐
PyPI
pypi.org › project › fpstimer
fpstimer · PyPI
>>> import fpstimer >>> timer = fpstimer.FPSTimer(60) # Make a timer that is set for 60 fps. >>> for i in range(100): # Each iteration of this loop will last (at least) 1/60 of a second. ... # Do calculations/work for a single "frame" here.
🌐
GitHub
github.com › yptheangel › opencv-starter-pack › blob › master › python › basic › calculate_FPS.py
opencv-starter-pack/python/basic/calculate_FPS.py at master · yptheangel/opencv-starter-pack
:computer::eyes: Small code snippets to help you get started for OpenCV application development - opencv-starter-pack/python/basic/calculate_FPS.py at master · yptheangel/opencv-starter-pack
Author: yptheangel
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 145530 › fps-how-to-divide-count-by-time-function-to-determine-fps
fps - how to divide count by time function to determine fps [closed] - OpenCV Q&A Forum
I've tried initializing time as fps_time = time.time fps_time = float(time.time) fps_time = np.float(time.time) fps_time = time() Then for calculating the fps, FPS = (counter / fps_time) FPS = float(counter / fps_time) FPS = float(counter (fps_time)) But errors I'm getting are object is not ...
🌐
YouTube
youtube.com › watch
How to add FPS to video and live in Opencv Python | Calculate frames per second - YouTube
How to calculate and add FPS to video in opencv python is shown#opencv
Published: October 21, 2022
🌐
pytz
pythonhosted.org › pyglet › programming_guide › the_frame_rate.html
The frame rate
You can determine your application's FPS with a single function call:
🌐
Python Programming
pythonprogramming.altervista.org › pygame-how-to-display-the-frame-rate-fps-on-the-screen
Pygame: how to display the frame rate (FPS) on the screen – python programming
January 14, 2020 - import pygame pygame.init() screen = pygame.display.set_mode((400,400)) clock = pygame.time.Clock() font = pygame.font.SysFont("Arial", 18) def update_fps(): fps = str(int(clock.get_fps())) fps_text = font.render(fps, 1, pygame.Color("coral")) return fps_text loop = 1 while loop: screen.fill((0, ...
🌐
Stack Overflow
stackoverflow.com › questions › 70757275 › how-to-calculate-fps-using-gpu-in-python
computer vision - How to calculate FPS using GPU in Python - Stack Overflow
January 18, 2022 - Once inferencing is done, I am taking fps_end_time and then subtracting the end time with start time and dividing time diff with frames to get FPS. This works fine if you are doing all your inferencing on CPU.
🌐
Blogger
kieleth.blogspot.com › 2014 › 03 › opencv-calculate-average-fps-in-python.html
Kieleth: OpenCv, calculate average fps in python
March 30, 2014 - def circular_counter(max): """helper ... get_tick_now(self): return cv2.getTickCount() @property def fps(self): fps = self.tick_frequency / (self.get_tick_now() - self.last_tick) self.l_fps_history[self.fps_counter.next() - 1] = fps return fps ...
🌐
TutorialsPoint
tutorialspoint.com › get-video-duration-using-opencv-python
Get video duration using OpenCV Python
May 31, 2023 - import cv2 # Create a sample video file path (replace with your video) video_path = 'sample_video.mp4' # Create video capture object cap = cv2.VideoCapture(video_path) # Get video properties fps = cap.get(cv2.CAP_PROP_FPS) total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT) # Calculate duration in seconds duration_seconds = total_frames / fps print(f"Video Duration: {duration_seconds:.2f} seconds") print(f"Total Frames: {total_frames}") print(f"FPS: {fps}") # Release the video capture object cap.release()
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › omniverse › archive › general discussion
API or SDK for calculating the current FPS on a Python - General Discussion - NVIDIA Developer Forums
June 27, 2023 - I want to write a program in Python which will 1: calculate fps of the current active window (game) or window by pid. 2: display the number of current fps in the selected location, on top of all applications, etc. For start, you can display in the upper left corner, let’s say in orange.