Spiegazione della routine 06-Video-Recording->gif_on_movement registra le animazioni di oggetti in movimento

# 录制移动物体动图
#
# 注意:您将需要SD卡来运行此示例。
#
# 您可以使用OpenMV Cam来录制gif文件。可以用于RGB565图或灰度图。
# 使用像GIMP这样的照片编辑软件在将GIF上传到网络之前对其进行压缩和优化。
#
# 此示例演示如何使用OpenMV的帧差异来进行运动检测。检测到运动后,
# 您的OpenMV摄像机将拍摄视频。

import sensor
import time
import gif
import os
import machine
import random

sensor.reset()  # 初始化sensor
sensor.set_pixformat(sensor.RGB565)  # 设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
sensor.set_framesize(sensor.QQVGA)  # 设置图像像素大小 QQVGA (160x120)
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()
    g = gif.Gif("example-%d.gif" % random.getrandbits(32), loop=True)

    clock = time.clock()  # 跟踪FPS帧率
    for i in range(100):
        clock.tick()
        # clock.avg() 返回帧与帧之间的毫秒数,其中包含gif延迟
        g.add_frame(sensor.snapshot(), delay=int(clock.avg() / 10))  # centiseconds.
        print(clock.fps())

    g.close()
    led.off()
    print("Restarting...")

Spiegazione ufficiale della funzione del documento cinese di Singtown Technology OpenMV:

Spiegazione ufficiale della funzione del documento cinese di Singtown Technology OpenMV:

Spiegazione ufficiale della funzione del documento cinese di Singtown Technology OpenMV:

results matching ""

    No results matching ""