结构相似性(SSIM)示例
import csi
import os
import time
MIN_TRIGGER_THRESHOLD = -0.4
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
csi0.auto_whitebal(False)
clock = time.clock()
if "temp" not in os.listdir():
os.mkdir("temp")
print("About to save background image...")
csi0.snapshot(time=2000)
csi0.snapshot().save("temp/bg.bmp")
print("Saved background image!")
while True:
clock.tick()
img = csi0.snapshot()
sim = img.get_similarity("temp/bg.bmp")
change = "- Change -" if sim.min < MIN_TRIGGER_THRESHOLD else "- No Change -"
print(clock.fps(), change, sim)