fps-如何通过时间除以计数以确定fps [英] fps - how to divide count by time function to determine fps
本文介绍了fps-如何通过时间除以计数以确定fps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个计数器在对每一帧进行计数.我要做的是将时间除以确定程序的FPS.但是我不确定如何在python中对计时功能执行操作.
I have a counter working that counts every frame. what I want to do is divide this by time to determine the FPS of my program. But I'm not sure how to perform operations on timing functions within 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'
But errors I'm getting are object is not callable or unsupported operand for /: 'int' and '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 秒内保持平均帧速率,则可以这样做(需要计数器):
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()
希望有帮助!
这篇关于fps-如何通过时间除以计数以确定fps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文