例程讲解-04-mean_adaptive_threshold_filter平均自适应阈值滤波
# 平均自适应阈值滤波示例。
#
# 此示例显示了使用自适应阈值处理的均值过滤。 当mean(threshold = True)时,
# mean()方法通过比较像素周围的像素的平均值减去偏移量来自适应阈值图像。
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内核等。
# 注意:您不应该使用大于2的值。
img.mean(1, 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.
原图:
运行效果图: