OPEN MV捕捉最大色块
import image,sensor,time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(100)
red=(8, 69, -4, 90, -42, 68) #设置阈值
white=(0, 55, -128, 127, -128, 127)
gress=(59, 39, -24, -66, 53, 19)
while(True):
img=sensor.snapshot()
all_blobs = img.find_blobs([red,white,gress],merge=True)#捕捉红、白、绿三色色块
blobs = img.find_blobs([gress])#捕捉绿色色块
white_blobs = img.find_blobs([white],merge=True)
gress_blobs = img.find_blobs([gress],merge=True)
s,x1,y1,w1,h1=0,0,0,0,0
for i in blobs:#此方法为在嵌有字典的列表中索引值,i为每一个字典
if i[2]*i[3] > s: #用类似冒泡排序一样找出色块最大面积
s = i[2]*i[3]
x1=i[0]
y1=i[1]
w1=i[2]
h1=i[3]
print("s",s)
img.draw_rectangle((x1,y1,w1,h1),color=(255,0,0))#画框语句位于while循环中,做到每帧画一次