# Untitled - By: Lenovo - 周三 9月 27 2023
import sensor, image, time
threshold_index = 2 # 0 for red, 1 for green, 2 for blue
thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
(30, 100, -64, -8, -32, 32), # generic_green_thresholds
(41, 64, -20, 6, -44, -28)] # generic_blue_thresholds
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[threshold_index]], pixels_threshold=200,area_threshold=200,merge=True):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(),blob.cy())
print(clock.fps())