Example: 02-Image-Processing/01-Image-Filters/mode_adaptive_threshold_filter.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Mode Adaptive Threshold Filter Example
#
# This example shows off mode filtering with adaptive thresholding.
# When mode(threshold=True) the mode() method adaptive thresholds the image
# 通过比较像素周围像素的模式减去偏移量与该像素。
# 避免在RGB565图像上使用模式滤波器。它会在图像边缘产生伪影...
import sensor
import time
sensor.reset() # 初始化相机传感器。
sensor.set_pixformat(sensor.GRAYSCALE) # 或 sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # 或 sensor.QVGA(或其他)
sensor.skip_frames(time=2000) # 让新设置生效。
clock = time.clock() # 跟踪FPS。
while True:
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # 拍照并返回图像。
# 中值滤波器的唯一参数是内核大小,可以是
# 0、1或2,分别对应1x1、3x3或5x5内核。
img.mode(1, threshold=True, offset=5, invert=True)
print(clock.fps()) # 注意:您的 OpenMV Cam 在连接到
# 计算机时运行速度会减半。断开连接后,FPS 应该会增加。