先进行口罩识别在进行二维码识别 但是在口罩识别完成之后没法进行二维码识别,请问下程序代码有什么问题吗
-
# Edge Impulse - OpenMV Image Classification Example import sensor, image, time, os, tf,pyb from pyb import Pin sensor.reset() # Reset and initialize the sensor. 重置感光元件 sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) 设置感光元件图像的色彩 sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) 设置感光元件分辨率大小 sensor.set_windowing((240, 240)) # Set 240x240 window. sensor.skip_frames(time=2000) # Let the camera adjust. 图像跳过几帧使以上设置生效 sensor.set_auto_gain(False) # 必须关闭此功能,以防止图像冲洗… pin8 = Pin('P8', Pin.OUT_PP, Pin.PULL_NONE) net = "trained.tflite" labels = [line.rstrip('\n') for line in open("labels.txt")] mask=False led = pyb.LED(2) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4. usb = pyb.USB_VCP() # This is a serial port object that allows you to clock = time.clock() #设置时钟 while(True): clock.tick() img = sensor.snapshot() img.lens_corr(1.8) # 1.8的强度参数对于2.8mm镜头来说是不错的。 软件畸变矫正 if mask==False : for obj in tf.classify(net, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5): print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect()) img.draw_rectangle(obj.rect()) # This combines the labels and confidence values into a list of tuples predictions_list = list(zip(labels, obj.output())) for i in range(len(predictions_list)): print("%s = %f" % (predictions_list[i][0], predictions_list[i][1])) if predictions_list[1][1] > 0.5 : #mask>0.5 戴口罩时,灯亮,蜂鸣器不响 led.on() pin8.value(0) #蜂鸣器不响 print ("请进行二维码识别") mask==True else : #不戴口罩时,蜂鸣器响,灯不亮 led.off() pin8.value(1) #蜂鸣器响 if led.on()and print ("请进行二维码识别") : mask==True if mask==True : for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color = (255, 0, 0)) message=code.payload() print(message) if message == "健康": led.on() pin8.value(0) #绿灯亮 蜂鸣器不响 #蜂鸣器8 LED7 print("进行体温监测") # return True # pin7.value(1) else : led.off() pin8.value(1) #蜂鸣器响 # pin7.value(0) #灯
-
你这个面条代码,我没法测试。估计就是哪里的逻辑有问题,多打印中间计算结果。