我在学颜色形状同时识别那个例程,然后想在里面加个框加个十字架标注一下我的圆的,但是就会报错,错误是list index out of range,想请教一下为什么
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
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()
red_threshold_01=(0,45,-28,82,-46,68)
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
for c in img.find_circles(threshold = 2000, x_margin = 20, y_margin = 20, r_margin = 20,
r_min = 2, r_max = 100, r_step = 2):
area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
#area为识别到的圆的区域,即圆的外接矩形框
statistics = img.get_statistics(roi=area)#像素颜色统计
print(statistics)
#(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
#l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
#以下为我自己改的部分
blobs = img.find_blobs([red_threshold_01])
if blobs :
print(blobs)
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#识别到的红色圆形用红色的圆框出来
img.draw_cross(blobs[5], blobs[6])
img.draw_rectangle(blobs[0:4])
#就这段话,报了错误为 list index out of range
else:
img.draw_rectangle(area, color = (255, 255, 255))
#将非红色的圆用白色的矩形框出来
print("FPS %f" % clock.fps())