# Untitled - By: xmc - Thu Aug 29 2024
import pyb, sensor, image, math, time
from pyb import UART
import ustruct
from image import SEARCH_EX, SEARCH_DS
sensor.set_contrast(1)
sensor.set_gainceiling(16)
clock = time.clock()
uart = UART(3,115200,bits=8, parity=None, stop=1, timeout_char = 1000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # 必须关闭此功能,以防止图像冲洗…
#sensor.skip_frames(20) # Let new settings take affect.
#sensor.set_auto_exposure(False, 1400)
sensor.set_auto_whitebal(False) # turn this off.
sensor.set_vflip(1)
sensor.set_hmirror(1)
clock = time.clock()
red_threshold = [(23, 58, 30, 70, -32, 24)]
green_threshold = [(45, 81, -74, -30, 10, 65)]
blue_threshold = [(55, 73, -65, -24, 17, 65)]
roi1=(96,53,98,88)
def sending_data(flag):
global uart;
data = ustruct.pack("<b",
flag
)
uart.write(data);
#a = 10
while(True):
#a = a + 1
#print(a)
clock.tick()
img = sensor.snapshot()
#print(clock.fps())
#img.lens_corr(1.8) # 消除桶形畸变 1.8的强度参数对于2.8mm镜头来说是不错的
for code in img.find_qrcodes():
img.draw_rectangle(code.rect(), color = (255, 0, 0))
message = code.payload()
print(message)
num1 = message[0]
num2 = message[1]
#print(num1)
#print(num1)
#if message:
b = 0
#print(b)
if num1 == '1':
print('get')
if num1 == '1':
red_blob = img.find_blobs(red_threshold, roi=roi1, area_threshold=3000)
if red_blob:
b = 1
if num1 == '2':
print(5)
green_blob = img.find_blobs(green_threshold, roi=roi1, area_threshold=300)
if green_blob:
b = 1
if num1 == '3':
blue_blob = img.find_blobs(blue_threshold, roi=roi1, area_threshold=3000)
if blue_blob:
b = 1
print(b)
if b == 1:
print("True")
#flag = 1
#print(flag)
#data = flag
#print(data)
#sending_data(data)
请问这个代码最后为什么打印不出true