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

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

import sensor, image, pyb, os

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.set_auto_whitebal(False) # Turn off white balance.

if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory

while(True):

    pyb.LED(RED_LED_PIN).on()
    print("About to save background image...")
    sensor.skip_frames(time = 2000) # Give the user time to get ready.

    pyb.LED(RED_LED_PIN).off()
    sensor.snapshot().save("temp/bg.bmp")
    print("Saved background image - Now detecting motion!")
    pyb.LED(BLUE_LED_PIN).on()

    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

    pyb.LED(BLUE_LED_PIN).off()
    print("Movement detected! Saving image...")
    sensor.snapshot().save("temp/snapshot-%d.jpg" % pyb.rng()) # Save Pic.

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

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

results matching ""

    No results matching ""