例程讲解-03-line_filter直线滤波

# 直线滤波例程
#
# 传感器模块可以在图像读取期间执行一些基本的图像处理而无需额外的开销。这个例子展示# 了如何在Python中应用一些基本的直线滤波。
#
# 警告 - 在Python中执行直线滤波时,此功能在M4上运行速度不够快。在将来,这可能会以# 某种方式被修复,现在你会看到一个部分帧缓冲区。

import sensor, image, time

# Initialize the camera sensor.
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
clock = time.clock() # Tracks FPS.

# Copy source to destination.
# Note source is YUYV destination is 1BPP Grayscale
def line_filter_copy(src, dst):
    for i in range(0, len(dst), 1):
        dst[i] = src[i<<1]

# Segment the image by following thresholds.按照阈值分割图像。
# Note source is YUYV destination is 1BPP Grayscale
def line_filter_bw(src, dst):
    for i in range(0, len(dst), 1):
        if (src[i<<1] > 200 and src[i<<1] < 255):
            dst[i] = 0xFF
        else:
            dst[i] = 0x00

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    lines = 0
    img = sensor.snapshot(line_filter = line_filter_copy) # Take a picture and return the image.
    #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.

results matching ""

    No results matching ""