• 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
🌐
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
Discussions

computer vision - How to calculate FPS using GPU in Python - Stack Overflow
I am working on a computer vision project where all the processing or inferencing is happening on GPU. I need to calculate live FPS I am getting from the video stream. This video stream cane be video More on stackoverflow.com
🌐 stackoverflow.com
January 18, 2022
How to calculate Frames Per Second in PyGame or just Python
clock = pygame.time.Clock() while True: do_stuff() clock.tick() fps = clock.get_fps() http://www.pygame.org/docs/ref/time.html More on reddit.com
🌐 r/learnpython
9
11
February 5, 2012
API or SDK for calculating the current FPS on a Python
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. More on forums.developer.nvidia.com
🌐 forums.developer.nvidia.com
0
0
June 27, 2023
How do I use YOLO v3 to achieve real time (>= 25 fps) object detecttion in a video?
I am in the same boat, but you are ahead of me. I just started experimenting with collab and Yolact++ on pre-recorded video. Following! More on reddit.com
🌐 r/computervision
42
14
January 25, 2020
🌐
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.
🌐
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 - It looks like below: cap = ... fps_end_time = datetime.datetime.now() time_diff = fps_end_time - fps_start_time fps = (total_frames / time_diff.seconds) fps_text = "FPS: {:.2f}".format(fps) print(fps_text) cv2.putText(frame, ...
🌐
pytz
pythonhosted.org › pyglet › programming_guide › the_frame_rate.html
The frame rate
Game performance is often measured in terms of the number of times the display is updated every second; that is, the frames-per-second or FPS. You can determine your application's FPS with a single function call: ... The value returned is more useful than simply taking the reciprocal of dt from a period function, as it is averaged over a sliding window of several frames. A simple way to ...
🌐
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
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › 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
July 15, 2025 - For calculating FPS, we will be keeping the record of the time when last frame processed and the end time when current frame processed.So, the processing time for one frame will be time difference between current time and previous frame time .
🌐
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
🌐
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
# Calculate FPS (Frames per second) · import cv2 · from timeit import default_timer as timer · · camera = cv2.VideoCapture(0) frame_count = 0 · total_time = 0 · · while camera.isOpened(): start_time = timer() _, frame = camera.read() frame_count += 1 ·
🌐
PyPI
pypi.org › project › fpstimer
fpstimer · PyPI
Running your program without an FPS timer could cause your program to run too fast for the user, especially as CPUs get faster. After running the code for a single frame, calling sleep() will pause the program for however much is needed for the remaining 1/10 second for that frame. This pause is calculated from the last time that sleep() was called for the previous frame. >>> 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.
🌐
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 ...
🌐
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]
🌐
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 ...
🌐
ActiveState
code.activestate.com › recipes › 579053-high-precision-fps
high precision FPS « Python recipes « ActiveState Code
May 12, 2015 - import time _tick2_frame = 0 _tick2_fps = 20000000 # real raw FPS _tick2_t0 = time.time() def tick(fps=60): global _tick2_frame, _tick2_fps, _tick2_t0 n = _tick2_fps / fps _tick2_frame += n while n > 0: n -= 1 if time.time() - _tick2_t0 > 1: _tick2_t0 = time.time() _tick2_fps = _tick2_frame _tick2_frame = 0 # while True: # tick(1) # 1 frame per second # print(_tick2_fps) # see adjustment in action # print(time.time()) ################################################################################ def tick(fps, callback): frame = 0 start = time.perf_counter() while True: callback() frame += 1
🌐
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
🌐
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 ·
🌐
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, ...
🌐
Roboflow
blog.roboflow.com › what-is-fps
What Is FPS? A Computer Vision Guide
July 31, 2026 - To calculate FPS, divide the number of frames processed by the total time taken to process those frames. For example, if 100 frames are processed in 2 seconds, the FPS would be calculated as follows: ... OpenCV and Python to calculate the FPS ...
🌐
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.