寻找色块
这个和之前的寻找绿色板块也是相似的语法。
find_blobs函数
image.find_blobs(thresholds, roi=Auto, x_stride=2, y_stride=1, invert=False, area_threshold=10, pixels_threshold=10, merge=False, margin=0, threshold_cb=None, merge_cb=None)
thresholds:颜色的阈值,这个参数是一个列表,可以包含多个颜色。如果你只需要一个颜色,那么在这个列表中只需要有一个颜色值,如果你想要多个颜色阈值,那这个列表就需要多个颜色阈值。
注意:在返回的色块对象blob可以调用code方法,来判断是什么颜色的色块。
red = (xxx,xxx,xxx,xxx,xxx,xxx)
blue = (xxx,xxx,xxx,xxx,xxx,xxx)
yellow = (xxx,xxx,xxx,xxx,xxx,xxx)
img=sensor.snapshot()
red_blobs = img.find_blobs([red])
color_blobs = img.find_blobs([red,blue, yellow])
roi:感兴趣区。
x_stride: 就是查找的色块的x方向上最小宽度的像素,默认为2,如果你只想查找宽度10个像素以上的色块,那么就设置这个参数为10:
blobs = img.find_blobs([red],x_stride=10)
y_stride: 就是查找的色块的y方向上最小宽度的像素,默认为1,如果你只想查找宽度5个像素以上的色块,那么就设置这个参数为5:
blobs = img.find_blobs([red],y_stride=5)
invert :反转阈值,把阈值以外的颜色作为阈值进行查找。
area_threshold :面积阈值,如果色块被框起来的面积小于这个值,会被过滤掉。
pixels_threshold :像素个数阈值,如果色块像素数量小于这个值,会被过滤掉。
merge: 合并,如果设置为True,那么合并所有重叠的blob为一个。
注意:这会合并所有的blob,无论是什么颜色的。如果你想混淆多种颜色的blob,只需要分别调用不同颜色阈值的find_blobs。
all_blobs = img.find_blobs(