Example: 02-Image-Processing/01-Image-Filters/grayscale_binary_filter.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 灰度二值滤波示例
#
# 此脚本展示了二值图像滤镜的功能。你可以传递任意
# 数量的阈值来分割图像。

import sensor
import time

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time=2000)
clock = time.clock()

low_threshold = (0, 50)
high_threshold = (205, 255)

while True:
    # 测试低阈值
    for i in range(100):
        clock.tick()
        img = sensor.snapshot()
        img.binary([low_threshold])
        print(clock.fps())

    # 测试高阈值
    for i in range(100):
        clock.tick()
        img = sensor.snapshot()
        img.binary([high_threshold])
        print(clock.fps())

    # 测试非低阈值
    for i in range(100):
        clock.tick()
        img = sensor.snapshot()
        img.binary([low_threshold], invert=1)
        print(clock.fps())

    # 测试非高阈值
    for i in range(100):
        clock.tick()
        img = sensor.snapshot()
        img.binary([high_threshold], invert=1)
        print(clock.fps())

results matching ""

    No results matching ""