例程讲解-04-median_adaptive_threshold_filter中值自适应阈值滤波

# 中值自适应阈值滤波示例。
# 此示例显示了使用自适应阈值处理的中值滤波。 当median(threshold=True) 时,
# median()方法通过比较像素周围的像素的中值减去偏移量来自适应阈值图像。
import sensor, image, time

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    # 第一个参数是内核大小。N对应于((N * 2)+1)^ 2内核大小。 
    # 例如。 1 == 3x3内核,2 == 5x5内核等。

    # 第二个参数“percentile”是从NxN邻域中选择的百分位数。 
    # 0.5是中位数,0.25是下四分位数,0.75是上四分位数。
    img.median(1, percentile=0.5, threshold=True, offset=5, invert=True)

    print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.

原图:

运行效果图:

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

results matching ""

    No results matching ""