Example: 02-Image-Processing/03-Frame-Differencing/on_disk_structural_similarity.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Structural Similarity (SSIM) Example
#
# 注意:运行此示例需要一张SD卡。
#
# This example shows off how to use the SSIM algorithm on your OpenMV Cam
# to detect differences between two images. The SSIM algorithm compares
# 8x8 blocks of pixels between two images to determine a similarity
# score between two images.

import sensor
import os
import time

# The image has likely changed if the sim.min() is lower than this.
MIN_TRIGGER_THRESHOLD = -0.4

sensor.reset()  # 初始化相机传感器。
sensor.set_pixformat(sensor.RGB565)  # 或 sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA)  # 或传感器.QQVGA(或其他规格)
sensor.skip_frames(time=2000)  # 让新设置生效。
sensor.set_auto_whitebal(False)  # 关闭白平衡。
clock = time.clock()  # 跟踪FPS。

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

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

while True:
    clock.tick()  # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot()  # 拍照并返回图像。
    sim = img.get_similarity("temp/bg.bmp")
    change = "- Change -" if sim.min() < MIN_TRIGGER_THRESHOLD else "- No Change -"

    print(clock.fps(), change, sim)

results matching ""

    No results matching ""