例程讲解20-Frame-Differencing->on_disk_basic_frame_differencing 需sd卡的简单帧差分

# 简单帧差分示例
#
# 注意:您需要一张SD卡才能运行此示例。
#
# 此示例演示了如何在OpenMV Cam中使用帧差异。 它被称为基本帧差异,因为没有背景图像更新。 
# 因此,随着时间的推移,背景图像可能会发生变化而导致问题。


import sensor, image, pyb, os, time

TRIGGER_THRESHOLD = 5

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 - Now frame differencing!")

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    # 用 "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) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.

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

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

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

results matching ""

    No results matching ""