python fps帮助计算

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python fps帮助计算相关的知识,希望对你有一定的参考价值。

fps = FPS().start() # initialize, it records starting time
fps.update() # this function does frame_count +=1
fps.stop() # it records ending time
print("avg fps:", fps.fps()) # prints the fps, by frame_count/(ending time - starting time)
import datetime

class FPS:
    def __init__(self):
        # store the start time, end time, and total number of frames
        # that were examined between the start and end intervals
        self._start = None
        self._end = None
        self._numFrames = 0

    def start(self):
        # start the timer
        self._start = datetime.datetime.now()
        return self
    
    def stop(self):
        # stop the timer
        self._end = datetime.datetime.now()

    def update(self):
        # increment the total number of frames examined during the
        # start and end intervals
        self._numFrames += 1

    def elapsed(self):
        # return the total number of seconds between the start and
        # end interval
        return (self._end - self._start).total_seconds()

    def fps(self):
        # compute the (approximate) frames per second
        return self._numFrames / self.elapsed()

以上是关于python fps帮助计算的主要内容,如果未能解决你的问题,请参考以下文章

python tools:计算视频的 FPS,以及总帧数

在 Pygame、Python 3 中设置固定的 FPS

不同fps的物理更新不同

如何准确计算 iOS 8 上硬件解码的 FPS?

动画FPS计算

Android 计算视频的fps