Example: 01-Camera/01-Video-Recording/mjpeg_on_movement.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 基于运动的MJPEG视频录制示例
#
# 注意:运行此示例需要一张SD卡。
#
# 你可以使用你的OpenMV Cam录制mjpeg文件。你可以向
# 录制器对象提供JPEG帧或RGB565/灰度帧。一旦你完成
# 录制Mjpeg文件,你可以使用VLC播放它。如果你在Ubuntu上
# 内置的视频播放器也能正常工作。
#
# 此示例演示了如何使用OpenMV摄像头进行帧差分
# 运动检测。检测到运动后,您的OpenMV Cam将开始录制视频。

import sensor
import time
import mjpeg
import os
import machine
import random

sensor.reset()  # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565)  # 将像素格式设置为RGB565 (or 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  # 我们会在10帧运动后检测到运动。
    while diff:
        img = sensor.snapshot()
        img.difference("temp/bg.bmp")
        stats = img.statistics()
        # Stats 5 是光照颜色通道的最大值。以下代码
        # 当整个图像的光照最大值超过20时触发。
        # 光照差异最大值通常应为零。
        if stats[5] > 20:
            diff -= 1

    led.on()
    m = mjpeg.Mjpeg("example-%d.mjpeg" % random.getrandbits(32))

    clock = time.clock()  # 跟踪FPS。
    for i in range(200):
        clock.tick()
        m.write(sensor.snapshot())
        print(clock.fps())

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

results matching ""

    No results matching ""