例程讲解06-Video-Recording->mjpeg_on_movement移动物体录像
import sensor
import time
import mjpeg
import os
import machine
import random
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_whitebal(False)
led = machine.LED("LED_RED")
if not "temp" in os.listdir():
os.mkdir("temp")
while True:
print("About to save background image...")
sensor.skip_frames(time=2000)
sensor.snapshot().save("temp/bg.bmp")
print("Saved background image - Now detecting motion!")
diff = 10
while diff:
img = sensor.snapshot()
img.difference("temp/bg.bmp")
stats = img.statistics()
if stats[5] > 20:
diff -= 1
led.on()
m = mjpeg.Mjpeg("example-%d.mjpeg" % random.getrandbits(32))
clock = time.clock()
for i in range(200):
clock.tick()
m.write(sensor.snapshot())
print(clock.fps())
m.close()
led.off()
print("Restarting...")
星瞳科技OpenMV官方中文文档函数讲解: