基础帧差示例
import csi
import os
import time
TRIGGER_THRESHOLD = 5
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 - Now frame differencing!")
while True:
clock.tick()
img = csi0.snapshot()
img.difference("temp/bg.bmp")
hist = img.get_histogram()
diff = hist.get_percentile(0.99).l_value - hist.get_percentile(0.90).l_value
triggered = diff > TRIGGER_THRESHOLD
print(clock.fps(), triggered)