logo

在识别颜色时有时出现帧超时是什么原因呢?

2023-10-22 19:38
U
stw1
04a3a73e-22e7-4d51-a16f-64c0541a8fd7.png
# 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())