例程讲解04-Image-Filters->basic_frame_differencing简单帧间差分

# 简单的帧间差分例子
#
# 注意: 为了运行这个程序,你需要插入SD卡。
#
# 这个例子示范了OpenMV的帧间差分
# 之所以叫做简单的帧间查分,是因为背景图片没有更新
# 所以,随着时间的推移,背景图片可能会改变,导致问题。

import sensor, image, os, time

sensor.reset() # 初始化sensor

sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
#设置图像色彩格式

sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
#设置图像像素大小

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

while(True):
    clock.tick() # 追踪两个snapshots()之间经过的毫秒数.
    img = sensor.snapshot() # 拍一张照片,返回图像

    # Replace the image with the "abs(NEW-OLD)" frame difference.
    img.difference("temp/bg.bmp")

    print(clock.fps()) # 注意: 当连接电脑后,OpenMV会变成一半的速度。当不连接电脑,帧率会增加。

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

results matching ""

    No results matching ""