Example: 02-Image-Processing/03-Frame-Differencing/on_disk_structural_similarity.py
import sensor
import os
import time
MIN_TRIGGER_THRESHOLD = -0.4
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_whitebal(False)
clock = time.clock()
if not "temp" in os.listdir():
os.mkdir("temp")
print("About to save background image...")
sensor.skip_frames(time=2000)
sensor.snapshot().save("temp/bg.bmp")
print("Saved background image!")
while True:
clock.tick()
img = sensor.snapshot()
sim = img.get_similarity("temp/bg.bmp")
change = "- Change -" if sim.min() < MIN_TRIGGER_THRESHOLD else "- No Change -"
print(clock.fps(), change, sim)