基础帧差示例

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 基础帧差示例
#
# 注意:运行此示例需要一张SD卡。
#
# 此示例演示了如何在OpenMV摄像头上使用帧差法。
# 之所以称为基础帧差,是因为没有背景图像更新。
# 因此,随着时间推移,背景图像可能发生变化并导致问题。

import csi
import os
import time

TRIGGER_THRESHOLD = 5

csi0 = csi.CSI()
csi0.reset()  # 重置并初始化传感器。
csi0.pixformat(csi.RGB565)  # 或csi.RGB565
csi0.framesize(csi.QVGA)  # 或csi.QQVGA(或其他)
csi0.snapshot(time=2000)  # 让新设置生效。
csi0.auto_whitebal(False)  # 关闭白平衡。
clock = time.clock()  # 跟踪FPS。

if "temp" not in os.listdir():
    os.mkdir("temp")  # 创建一个临时目录

print("About to save background image...")
csi0.snapshot(time=2000)  # 给用户时间准备。
csi0.snapshot().save("temp/bg.bmp")
print("Saved background image - Now frame differencing!")

while True:
    clock.tick()  # 跟踪snapshots()之间经过的毫秒数。
    img = csi0.snapshot()  # 拍照并返回图像。

    # 将图像替换为“abs(NEW-OLD)”帧差结果。
    img.difference("temp/bg.bmp")

    hist = img.get_histogram()
    # 下面的代码通过比较第99百分位值(即
    # 非离群的最大值)与第90百分位值(即非最大
    # 值)来工作。当差异图像中有更多像素变化时,
    # 这两个值之间的差距会增大。
    diff = hist.get_percentile(0.99).l_value - hist.get_percentile(0.90).l_value
    triggered = diff > TRIGGER_THRESHOLD

    print(clock.fps(), triggered)  # 注意:您的 OpenMV Cam 在连接到
    # 计算机时运行速度会减半。断开连接后,FPS 应该会增加。

results matching ""

    No results matching ""