例程讲解05-Snapshot->snapshot_on_movement拍摄移动物体

# 拍摄移动物体
#
# 注意:您将需要SD卡来运行此示例。
#
# 此示例演示如何使用OpenMV的帧差异来进行运动检测。运动检测后,您的
# OpenMV将拍摄照片。

import sensor
import random
import os
import machine

sensor.reset()  # 初始化sensor
sensor.set_pixformat(sensor.RGB565)  # 设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
sensor.set_framesize(sensor.QVGA)  # 设置图像像素大小 QVGA (320x240)
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  # We'll say we detected motion after 10 frames of motion.
    while diff:
        img = sensor.snapshot()
        img.difference("temp/bg.bmp")
        stats = img.statistics()
        # state[5]是照明颜色通道的最大值。当整个图像的最大光照高于20时
        # 触发下面的代码。
        # 照明差异最大值应该为零。
        if stats[5] > 20:
            diff -= 1

    led.on()
    print("Movement detected! Saving image...")
    sensor.snapshot().save("temp/snapshot-%d.jpg" % random.getrandbits(32))  # Save Pic.
    led.off()

星瞳科技OpenMV官方中文文档函数讲解:

星瞳科技OpenMV官方中文文档函数讲解:

results matching ""

    No results matching ""