openmv颜色识别--多颜色识别

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)
//merge=True 色块合并
多颜色识别核心代码
thresholds = [
(30, 100, 15, 127, 15, 127), # generic_red_thresholds
(30, 100, -64, -8, -32, 32), # generic_green_thresholds
(0, 15, 0, 40, -80, -20),
] # generic_blue_thresholds

for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200)😕/多颜色
for blob in img.find_blobs([thresholds[0]],merge=True, pixels_threshold=200, area_threshold=200)😕/单颜色

blob.code() 返回一个16bit数字,每一个bit会对应每一个阈值。举个例子:

blobs = img.find_blobs([red, blue, yellow], merge=True)

如果这个色块是红色,那么它的code就是0001,如果是蓝色,那么它的code就是0010。注意:一个blob可能是合并的,如果是红色和蓝色的blob,那么这个blob就是0011。这个功能可以用于查找颜色代码。也可以通过blob[8]来获取。

print(blob.code())可以反映当前检测到的颜色
注意python中空格的意义!!!

posted @ 2025-02-06 13:06  二九二  阅读(102)  评论(0)    收藏  举报