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().
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 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)
Use pyb.millis() to record the begining time.
Then after a period of time,deviate,calculate the time duriation.