import sensor, image, time
pink_threshold =(44, 75, 8, 77, -44, 21)
yellow_threshold = (36, 75, -20, 11, 23, 48)
blue_threshold = (61, 95, -23, -10, -30, -10)
green_threshold =(50, 60, -48, -30, 15, 38)
pink_color_code = 1
yellow_color_code = 2
blue_color_code = 4
green_color_code = 8
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_whitebal(False)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([pink_threshold, yellow_threshold , blue_threshold , green_threshold], area_threshold=100)
if blobs:
for blob in blobs:
x = blob[0]
y = blob[1]
width = blob[2]
height = blob[3]
center_x = blob[5]
center_y = blob[6]
color_code = blob[8]
if color_code == pink_color_code:
img.draw_string(x, y - 10, "red", color = (0xFF, 0x00, 0x00))
elif color_code == blue_color_code:
img.draw_string(x, y - 10, "blue", color = (0xFF, 0x00, 0x00))
elif color_code == yellow_color_code:
img.draw_string(x, y - 10, "yellow", color = (0xFF, 0x00, 0x00))
elif color_code == green_color_code:
img.draw_string(x, y - 10, "green", color = (0xFF, 0x00, 0x00))
img.draw_rectangle([x, y, width, height])
img.draw_cross(center_x, center_y)
print(clock.fps())