import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
def find_max(blobs):
max_size=0
for blob in blobs:
if blob.pixels() > max_size:
max_blob=blob
max_size = blob.pixels()
return max_blob
thresholds = [(27, 67, 19, 91, 45, 76), # 红色
(27, 90, -3, -28, 31, 125),# 绿色
(0, 30, -20, 30, -40, 50)] # 蓝色
threshold = [50, 50, 0, 0, 0, 0] # Middle L, A, B values.
clock = time.clock()
while(True):
# clock.tick()
img = sensor.snapshot()
# for blob in img.find_blobs(thresholds, pixels_threshold=10, area_threshold=10):
blobs = img.find_blobs(thresholds, pixels_threshold=20, area_threshold=20, merge=True)
if blobs:
max_blob=find_max(blobs )
print(max_blob.code())
for blob in blobs:
if blob.code():
img.draw_cross(blob.cx(), blob.cy())
img.draw_rectangle(blob.rect())我的代码是这样的,识别红绿蓝,并返回最大色块的颜色,请问blob.code()返回的是各个颜色的标号吗,默认值是多少?
代码总是返回三种颜色合成色块的集合,code返回的数不是1、2、4..而是5、7等等的集合,该怎么修改呢?
https://book.openmv.cc/project/zhui-xiao-qiu-de-xiao-8f665d28-project-pan-tilt-md.html#%E8%B0%83%E6%95%B4%E5%8F%82%E6%95%B0%EF%BC%8C%E5%AE%9E%E7%8E%B0%E8%B7%9F%E9%9A%8F
看find_max函数。