如果是从左到右排序的话,可以用sorted函数,key就是中心横坐标。
import sensor, image, time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
green_threshold = (10,100,-30,40,-50,60)#随便写的,需要重新设置阈值
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([green_threshold])
blobs = sorted(blobs,key=lambda b:b.cx())
for i in range(len(blobs)):
print(i, blobs[i])
print(clock.fps())