openmv颜色例程问题
-
# 多颜色组合识别 。 import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs(thresholds, pixels_threshold=100, area_threshold=100, merge=True): if blob.code() == 3: # r/g code img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_string(blob.x() + 2, blob.y() + 2, "r/g") if blob.code() == 5: # r/b code img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_string(blob.x() + 2, blob.y() + 2, "r/b") if blob.code() == 6: # g/b code img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_string(blob.x() + 2, blob.y() + 2, "g/b") if blob.code() == 7: # r/g/b code img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_string(blob.x() + 2, blob.y() + 2, "r/g/b") print(clock.fps())
blob.code=? 这个数字是因为红色色块是1,绿色是2,蓝色是4吗,怎么得来的。如果我只想判断是否是红色色块是不是就是 blob.code=1,绿色就是 blob.code=2
-
block.code()是组合色块。
如果你的目标只有一个颜色,完全可以
红色色块们 = img.find_blobs(红色) 绿色色块们 = img.find_blobs(绿色) 黄色色块们 = img.find_blobs(黄色)