Record lag time

Assuming that after running the procedure,the image will stop from time to time,which indicates that the FPS is small.

Count FPS

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

Track frame per second through time.clock().

Calculate consumed time

If frame per second is small.then you can calculate time of different process through millis().You can measure where exactly consume the more time in the procedure.

Example:

import pyb

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

Use pyb.millis() to record the begining time.

Then after a period of time,deviate,calculate the time duriation.

results matching ""

    No results matching ""