记录耗费时间

假如运行程序后,图像一卡一卡的,那么说明帧率小.

计算帧率

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(10)              # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps())

通过time.clock()可以追踪帧率。

计算耗费的时间

如果帧率小,那么可以通过millis()来计算不同过程的时间。 可以测量出到底是程序哪里耗费时间多。

例子:

import pyb

time_start = pyb.millis()
img = sensor.snapshot()         # Take a picture and return the image.
duration = pyb.elapsed_millis(time_start)

使用pyb.millis()记录开始时间

然后过一段时间,做差,计算出经历的时间duration

results matching ""

    No results matching ""