记录耗费时间

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

计算帧率

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 sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):
    time_start = time.ticks_ms()
    img = sensor.snapshot()
    time_end = time.ticks_ms()
    print(time_end - time_start)

使用time.ticks_ms()记录时间

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

results matching ""

    No results matching ""