在openmv中,当外界通过串口向openmv发送‘1’时,openmv会一直开启工作模式,但是在我写的程序中,在串口接收到数据中为什么只有执行一次,为什么不能无限执行
import sensor, image, time
from pyb import UART
uart = UART(3, 115200)
green_threshold = (14, 80, 19, -25, -67, -24)
#(35, 75, -7, -22, -47, -20)
#(36, 76, -88, 65, -110, -21)
#(27, 80, 15, -22, -47, -20)
#(18, 74, 53, -91, -78, -24)
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
#关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
def delay1():#对画面进行延迟,不影响ide中的画面流畅度,并对串口发送数据进行延迟
for i in range(45):
sensor.snapshot()
if i == 42:
uart.write('1')
def delay2():#对画面进行延迟,不影响ide中的画面流畅度,并对串口发送数据进行延迟
for i in range(45):
sensor.snapshot()
if i == 42:
uart.write('2')
def delay3():#对画面进行延迟,不影响ide中的画面流畅度,并对串口发送数据进行延迟
for i in range(45):
sensor.snapshot()
if i == 42:
uart.write('3')
def delay4():#对画面进行延迟,不影响ide中的画面流畅度,并对串口发送数据进行延迟
for i in range(45):
sensor.snapshot()
if i == 42:
uart.write('4')
def delay5():#对画面进行延迟,不影响ide中的画面流畅度,并对串口发送数据进行延迟
for i in range(45):
sensor.snapshot()
if i == 42:
uart.write('5')
clock = time.clock() # Tracks FPS.
def find_c(threshold,roi):
number=0
max_size=0
blobs = img.find_blobs(threshold,roi=roi,x_stride=10, y_stride=50)
for b in blobs:
if b[2]*b[3] > max_size:
max_size = b[2]*b[3]
if max_size>200 and b[2]>20:
if b[3]>20 and b[2]>20:
max_size=max_size
img.draw_rectangle(b[0:4], color = (0, 0, 0))
img.draw_cross(b[5], b[6], color = (0, 0, 0))
number=b[5]
return number
def read():
a=0
if uart.any():
a=int(uart.read())
print(a)
return a
def find_max(blobs):
max_size=0
max_blob=[]
for blob in blobs:
if blob[2]*blob[3] > max_size:
max_blob=blob
max_size = blob[2]*blob[3]
return max_blob
def max_area(blobs):
max_size=0
max_blob=[]
for blob in blobs:
if blob[2]*blob[3] > max_size:
max_blob=blob
max_size = blob[2]*blob[3]
return max_size
t=0
b=0
a=1
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
blobs = img.find_blobs([green_threshold])
roi1=[0,0,40,120]
roi2=[120,0,40,120]
blobs3 = img.find_blobs([green_threshold],roi=roi2)
blobs2 = img.find_blobs([green_threshold],roi=roi1)
#if uart.any():
# a=int(uart.read())
# print(a)
#return a
if b==0:
a=read()
if a==1:
b=1
elif a==2:
b=2
elif a==3:
b=3
#if blobs:
if b==1 and t==0:
#print(111)
if blobs:
print(111)
for b in blobs:
max_blob = find_max(blobs)
if max_blob[2]*max_blob[3]>1500 :
area=max_blob[2]*max_blob[3]
img.draw_rectangle(max_blob[0:4])
#print(max_blob[5])
if 70<max_blob[5]<90 :
print(max_blob[2])
if max_blob[2]>70:
delay1()
print(1)
t=t+1
else:
print(4)
delay4()
elif max_blob[5]<71 :
print(2)
delay2()
elif max_blob[5]>91:
print(3)
delay3()
if b==2 :
print(666)
blobs = img.find_blobs([green_threshold])
if blobs:
for b in blobs:
max_blob = find_max(blobs)
if max_blob[2]*max_blob[3]>1500 :
print(5)
delay5()
t=t+1
#print(5)
#xdelay5()
if b==3 :
print(1)你的代码里,
a是什么用处,b是什么用处,t是什么用处?