文章目录
前言
本文仅仅简单介绍了Openmv中常见的图像处理操作(灰度化、掩膜、二值化、腐蚀、膨胀、缩放、旋转、平移、边缘检测、轮廓检测)
1. 灰度化(Grayscale)
将彩色图像转换为灰度图像,减少计算量。
实现方法:
import sensor
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE) # 设置为灰度模式
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
while True:
img = sensor.snapshot() # 捕获灰度图像
2. 二值化(Thresholding)
将灰度图像转换为黑白图像,通过设定阈值分离目标区域。
实现方法:
import sensor
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
threshold = (100, 255) # 阈值范围
while True:
img = sensor.snapshot()
img.binary([threshold]) # 二值化处理
3. 掩膜(Mask)
通过掩膜操作提取图像中的特定区域。
实现方法:
import sensor, image
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize