例程讲解20-Frame-Differencing->on_disk_shadow_removal 需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.QQVGA) # or sensor.QVGA (or others)
if sensor.get_id() == sensor.OV7725: # Reduce sensor PLL from 6x to 4x.
    sensor.__write_reg(0x0D, (sensor.__read_reg(0x0D) & 0x3F) | 0x40)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.set_auto_whitebal(False) # Turn off white balance.
sensor.set_auto_gain(False) # Turn this off too.
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.

    # 请注意,要移除阴影,背景图像必须无阴影,并且与最新图像具有相同的光照。 
    # 与max()不同,阴影去除不会删除所有暗物体,除非它们是阴影...

    # 用 "abs(NEW-OLD)" 帧差替换图像。
    img.remove_shadows("temp/bg.bmp").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 ""