二值化

彩色二值化滤波

备注

LAB格式下通过设置颜色范围进行二值化操作

红色过滤器 绿色过滤器 蓝色过滤器

code

# Color Binary Filter Example
#
# This script shows off the binary image filter. This script was originally a
# test script... but, it can be useful for showing how to use binary.

import pyb, sensor, image, math

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)

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):

    # Test red threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([red_threshold])
    # Test green threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([green_threshold])
    # Test blue threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([blue_threshold])
    # Test not red threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([red_threshold], invert = 1)
    # Test not green threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([green_threshold], invert = 1)
    # Test not blue threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([blue_threshold], invert = 1)

灰度图二值化

# Grayscale Binary Filter Example
#
# This script shows off the binary image filter. This script was originally a
# test script... but, it can be useful for showing how to use binary.

import pyb, sensor, image, math

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

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

while(True):
    # Test low threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([low_threshold])
    # Test high threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([high_threshold])
    # Test not low threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([low_threshold], invert = 1)
    # Test not high threshold
    for i in range(100):
        img = sensor.snapshot()
        img.binary([high_threshold], invert = 1)
Copyright 杭州云江科技有限公司 2017 all right reserved,powered by Gitbook该文件修订时间: 2018-04-02 09:53:12

results matching ""

    No results matching ""