Routine explanation -04-mean_filter Mean filtering
This routine is 04-image-Filters-mean_filter.py\ The purpose of this routine is to filter the image to the average, so that the image to achieve the fuzzy effect, the average filter is the fastest filter.
# 均值滤波例程
#
# 这个例子展示了均值滤波。均值滤波是NxN邻域的标准均值滤波。
# 均值滤波通过模糊所有内容来消除图像中的噪点。
# 但是,这是最快的内核过滤器操作
import sensor, image, time
sensor.reset() # 初始化sensor
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
#设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
#设置图像像素大小
sensor.skip_frames(time = 2000) # 让新的设置生效
clock = time.clock() # 跟踪FPS帧率
while(True):
clock.tick() # 追踪两个snapshots()之间经过的毫秒数.
img = sensor.snapshot() # 拍一张照片,返回图像
# The only argument is the kernel size. N coresponds to a ((N*2)+1)^2
# kernel size. E.g. 1 == 3x3 kernel, 2 == 5x5 kernel, etc. Note: You
# shouldn't ever need to use a value bigger than 2.
# 唯一的参数是内核大小。N对a ((N*2)+1)^2的核大小有响应。
# 例如:1 == 3x3内核,2 == 5x5内核,等等。
# 注意:不应该使用大于2的值。
img.mean(1)
#image.mean(size),size为核的大小,size=1则是3x3的核,size=2则是5x5的核
print(clock.fps()) # 注意: 当连接电脑后,OpenMV会变成一半的速度。当不连接电脑,帧率会增加。
original image:
After mean filtering:
Singtown Technology OpenMV official Chinese document function explanation: