gpt4 book ai didi

python - fps - 如何将计数除以时间函数以确定 fps

转载 作者:太空狗 更新时间:2023-10-30 00:27:28 26 4
gpt4 key购买 nike

我有一个计数器可以计算每一帧。我想做的是将其除以时间以确定我的程序的 FPS。但是我不确定如何在 python 中对计时函数执行操作。

我试过将时间初始化为

fps_time = time.time 
fps_time = float(time.time)
fps_time = np.float(time.time)
fps_time = time()

然后计算fps,

FPS = (counter / fps_time)
FPS = float(counter / fps_time)
FPS = float(counter (fps_time))

但我得到的错误是对象不可调用或/: 'int' 和 'buildin functions' 的操作数不受支持

在此先感谢您的帮助!

最佳答案

  • 这是在每一帧打印程序的帧速率的非常简单的方法(不需要计数器):

    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
  • 如果您想要x 秒内的平均 帧速率,您可以这样做(需要计数器):

    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()

希望对您有所帮助!

关于python - fps - 如何将计数除以时间函数以确定 fps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43761004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com