想识别一个红色的物体,识别到输出1,没有识别到输出0,但是我再运行时,总是输出1,即便没有看到红色的物体,下面是我的代码:
import sensor, image, time, math,pyb
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()
thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
(30, 100, -64, -8, -32, 32), # generic_green_thresholds
(0, 30, 0, 64, -128, 0)] # generic_blue_thresholds
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([thresholds[0]], pixels_threshold=50, area_threshold=100, merge=True)
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
if blob :
print(1)
else:
print(0)希望高人指点指点
如果blobs是空的,for blob in blobs:里面就不会执行,也就是永远不会输出0