颜色二值化滤镜示例

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

import csi
import time

csi0 = csi.CSI()
csi0.reset()
csi0.framesize(csi.QVGA)
csi0.pixformat(csi.RGB565)
csi0.snapshot(time=2000)

clock = time.clock()

# 使用工具 -> 机器视觉 -> 阈值编辑器来选择更好的阈值。
red_threshold = (0, 100, 0, 127, 0, 127)  # L A B
green_threshold = (0, 100, -128, 0, 0, 127)  # L A B
blue_threshold = (0, 100, -128, 127, -128, 0)  # L A B

while True:
    # 测试红色阈值
    for i in range(100):
        clock.tick()
        img = csi0.snapshot()
        img.binary([red_threshold])
        print(clock.fps())

    # 测试绿色阈值
    for i in range(100):
        clock.tick()
        img = csi0.snapshot()
        img.binary([green_threshold])
        print(clock.fps())

    # 测试蓝色阈值
    for i in range(100):
        clock.tick()
        img = csi0.snapshot()
        img.binary([blue_threshold])
        print(clock.fps())

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

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

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

results matching ""

    No results matching ""