例程讲解20-Frame-Differencing->on_disk_structrual_similarity 需sd卡的结构相似性帧差分

# 结构相似性(SSIM)示例
#
# 注意:您需要一张SD卡才能运行此示例。
#
# 此示例展示了如何在OpenMV Cam上使用SSIM算法来检测两个图像之间的差异。 
# SSIM算法比较两个图像之间的8×8像素块以确定两个图像之间的相似性得分。

import sensor, image, pyb, os, time

# 如果sim.min() 低于此值,则图像可能已更改。
MIN_TRIGGER_THRESHOLD = -0.4

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.
clock = time.clock() # Tracks FPS.

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

print("About to save background image...")
sensor.skip_frames(time = 2000) # Give the user time to get ready.
sensor.snapshot().save("temp/bg.bmp")
print("Saved background image!")

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.
    sim = img.get_similarity("temp/bg.bmp")
    change = "- Change -" if sim.min() < MIN_TRIGGER_THRESHOLD else "- No Change -"

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

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

results matching ""

    No results matching ""