logo

OPENMV4怎么把if语句中执行后的数传递到语句外使用?

2021-01-15 21:01
G
iuk4
import sensor, image, time
green_threshold   = (18, 37, -6, 26, -72, -25)
sensor.reset() 
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QVGA) 
sensor.skip_frames(time = 2000) 
clock = time.clock() 

while(True):
    
    clock.tick() 
    img = sensor.snapshot() 
    colour_blobs = img.find_blobs([green_threshold],area_threshold=1000)
    
    if colour_blobs:   
        for b in colour_blobs:
          img.draw_rectangle(b[0:4]) 
          img.draw_cross(b[5], b[6]) 
          print(b[5])                              
          if b[5] >= 200:
                a=b[8]
            #print("a=",a)
          elif b[5] <= 100:
                b=b[8]
            #print("b=",b)
          else :
                c=b[8]
            #print("c=",c)

目的:print(a,b,c) #此语句一直错误,不知道怎么写

(x轴分三部分,把这三部分在if语句中处理的颜色编号1,2,4传递到if语句外面使用)

2021-01-18 18:30
I
网红小智智 星瞳科技

在while(True)上面一行写

a=0
b=0
c=0