import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
clock = time.clock()
red_threshold_01 =((35,100,41,77,24,59));
green_threshold_01 =((79,62,-57,-16,12,74));
yello_threshold_01 =((59,100,-60,10,9,127));while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([red_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10);#红色物块
blobs1 = img.find_blobs([green_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10);#绿色物块
blobs2 = img.find_blobs([yello_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10);#黄色物块if blobs:#如果找到了目标颜色print("red")for b in blobs:#迭代找到的目标颜色区域# Draw a rect around the blob.
img.draw_rectangle(b[0:4])# rect#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6])# cx, cy#在目标颜色区域的中心画十字形标记elif blobs1:#如果找到了目标颜色print("green")for b in blobs1:#迭代找到的目标颜色区域# Draw a rect around the blob.
img.draw_rectangle(b[0:4])# rect#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6])# cx, cy#在目标颜色区域的中心画十字形标记elif blobs2:#如果找到了目标颜色print("yello")for b in blobs2:#迭代找到的目标颜色区域# Draw a rect around the blob.
img.draw_rectangle(b[0:4])# rect#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6])# cx, cy#在目标颜色区域的中心画十字形标记