一、openmv图像处理基础
1.sensor.reset() 初始化感光元件
2.sensor.set_pixformat() 设置像素模式
--sensor.GRAYSCALE: 灰度,每个像素8bit
--sensor.RGB565: 彩色,每个像素16bit
3.sensor.set_framesize() :设置图像的大小
4.sensor.skip_frames(n=10): 跳过n张照片,在更改设置后,跳过一些帧,等待感光元件变稳定
5.sensor.snapshot(): 拍摄一张照片,返回一个image对象
6.sensor.set_auto_gain() :自动增益开启(True)或者关闭(False)
7.sensor.set_auto_whitebal() :自动白平衡开启(True)或者关闭(False)
8.sensor.set_auto_exposure(enable[\, exposure_us]):自动曝光,exposure_us为设置曝光时间,微秒为单位
9.sensor.set_windowing(roi):设置要处理的区域大小
(注:ROI的格式为感兴趣区域的左上角的x、y坐标以及其宽度w和高度h)
10.sensor.set_hmirror(True)
水平方向翻转
11.sensor.set_vflip(True)
垂直方向翻转
二、图像绘制方法
1.image.draw_line(line_tuple, color=White) 在图像中画一条直线
2.image.draw_rectangle(rect_tuple, color=White) 在图像中画一个矩形框
3.image.draw_circle(x, y, radius, color=White) 在图像中画一个圆
4.image.draw_cross(x, y, size=5, color=White) 在图像中画一个十字
5.image.draw_string(x, y, text, color=White) 在图像中写字 8x10的像素
注:x,y为坐标,text为要写的字符串
示例代码:
image.draw_line((0, 0,100, 100), color=White)
image.draw_rectangle((50, 50,100, 100), color=White)
image.draw_circle((75, 75), 30, color=White)
image.draw_cross((100, 100), size=10, color=White)
image.draw_string(10, 10, 'OpenMV', color=White)
三、色块识别
1. find_blobs函数详解
使用find_blobs函数识别图像中的色块,并根据需要过滤色块。
2. 参数解释与实际应用
x_stride和y_stride: 色块的最小宽度
invert: 反转阈值
area_threshold和pixels_threshold: 面积和像素数量的阈值
merge: 是否合并重叠的blob
3.识别图像中色块的示例代码:
thresholds = (100, 200, 255)
blobs = image.find_blobs(thresholds)
for blob in blobs:
x, y, w, h = blob.rect()
image.draw_rectangle(blob.rect(), color=(255, 0, 0))