K210口罩+人脸分辨+自学习+测温+串口屏

该代码实现了一个基于MaixPy的系统,用于通过串口通信进行指令交互,并使用KPU进行口罩检测。当接收到特定串口指令时,系统会读取并处理摄像头捕获的图像,识别是否佩戴口罩,并将结果通过串口发送出去。此外,还实现了人脸特征值的存储和比对功能,用于注册和验证用户。
摘要由CSDN通过智能技术生成

视频在这里啊
https://www.bilibili.com/video/BV1F64y1t76P?spm_id_from=333.999.0.0

import sensor
import image
import lcd
import KPU as kpu
import time
from Maix import FPIOA, GPIO
import gc
from fpioa_manager import fm
from board import board_info
import utime
A_1=A_2=0
B_1=B_2=B_3=B_4=0
j_1=j_4=0
j_2=j_3=1
#******************串口定义*******************
from fpioa_manager import fm
fm.register(1, fm.fpioa.UART1_TX, force=True)
fm.register(17, fm.fpioa.UART1_RX, force=True)
fm.register(2, fm.fpioa.UART2_TX, force=True)
fm.register(3, fm.fpioa.UART2_RX, force=True)
from machine import UART
uart_A = UART(UART.UART1, 9600, 8, 0, 0, timeout=1000, read_buf_len=4096)
uart_B = UART(UART.UART2, 115200, 8, 1, 0, timeout=1000, read_buf_len=4096)
data=bytearray([0xFF,0xFF,0xFF])
#******************图框颜色********************
color_R = (255, 0, 0)
color_G = (0, 255, 0)
color_B = (0, 0, 255)
#******************口罩子程序,显示在img********************
def drawConfidenceText(image, rol, classid, value):
    global A_1
    global A_2
    global j_3
    text = ""
    _confidence = int(value * 100)

    if classid == 1:
        text = 'mask: ' + str(_confidence) + '%'
        A_1=A_1+1
        if(A_1==10):
          print("识别到了口罩")
          uart_A.write("click b0,1")
          uart_A.write(data)
          if(j_3==1):
            uart_B.write("6"+'\r''\n')
            j_3=0
          A_1=0
    else:
        text = 'no_mask: ' + str(_confidence) + '%'
        A_2=A_2+1
        if(A_2==10):
          print("未识别到口罩")
          uart_A.write("click b0,0")
          uart_A.write(data)
          if(j_3==0):
            uart_B.write("5"+'\r''\n')
            j_3=1
          A_2=0
    image.draw_string(rol[0], rol[1], text, color=color_R, scale=2.5)

class_IDs = ['no_mask', 'mask']
#******************加载模型分别是196特征值和mask(口罩和人脸)********************
task_fe = kpu.load("/sd/5.smodel")
task = kpu.load("/sd/mask.kmodel")

clock = time.clock()
#******************定义boot按键********************
fm.register(board_info.BOOT_KEY, fm.fpioa.GPIOHS0)
key_gpio = GPIO(GPIO.GPIOHS0, GPIO.IN)

#******************不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂不懂********************
start_processing = False
BOUNCE_PROTECTION = 50
def set_key_state(*_):
    global start_processing
    start_processing = True
    utime.sleep_ms(BOUNCE_PROTECTION)
key_gpio.irq(set_key_state, GPIO.IRQ_RISING, GPIO.WAKEUP_NOT_SUPPORT)
#******************头文件********************
lcd.init()
sensor.reset(dual_buff=True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(1)
sensor.set_vflip(0)
sensor.run(1)
#******************加载模型分别是196特征值和mask(口罩和人脸)********************
anchor = (0.1606, 0.3562, 0.4712, 0.9568, 0.9877, 1.9108, 1.8761, 3.5310, 3.4423, 5.6823)  # anchor for face detect
dst_point = [(44, 59), (84, 59), (64, 82), (47, 105),
             (81, 105)]  # standard face key point position
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
b = kpu.init_yolo2(task_fe, 0.5, 0.3, 5, anchor)
#******************窗口大小********************
img_lcd = image.Image()
img_face = image.Image(size=(128, 128))
a = img_face.pix_to_ai()
#******************人脸特征值储存********************
record_ftr = []
record_ftrs = [b'\xd9\xfe\xd3\xe2\xea\x80>\xddJ8\\\x12\x0fO\xc2\xe1`L\t\xce\xea\xa9/\x80\xc2<\xcc\xe6\x15\x12\x02\x15/\\\xe5\xe6[\xffS\x12\xb5V\x15.\xc4P\x1e\xb9!\x17a\xaa\x80\xdd\xc8g\xe5\xe6\xe3F\xc6\xe37P*\xbd#\xee\xf9\x11\x06\xc9\xfe\x11\xb0\xc9\x95\xa8\x06\xf2\xd0\x0f\x9f\t\xe5\x80\x02\x1f\xd2\x11\x9dLP\x12H\xd0\x1b\xff\xf1g\xfa\x9ds\xd1T\xf2)C\xdf\xd9k\x03\xd0\xda\xfb"\xf3\xdb\xff\x0b\x07\x02\x1d\xa1\x80\tN\xce\x80\x15\xc9\xdf;\xd1`\x0ep\x80\x1b\xbe\x80X\x03\x02\x80\xc2\xdd\xea\xdd\xca@B\xde!\x01/\xf9\xce+\xc1g\x80\xa4\xee\xf1\xa8\x15\xe5"\x8c\x15\xfb\x80)\xebO8\x80\xf5\x91\xb1\xde\xf3D\x15\xda\x80\x80\x99Pa2&\x80!3',
               b'\xd0\xf7\xc5\xe1\n\x80C\xd5-7\x80S\xedZ\xcc\xc9<\x19\xed\xf6\xea\xbd\x16\x80\xb5D\xf1\xfd\x1d/\xf5C&\x80\x0e\ni\xf9#\xf9\xd2.\x1fN\xb1?\r\x89!\r\x7f\xaa\x80\xbd\xad:\xbe\xf3\xf3R\xc2\xeb@}3\xb1\x0f\x01\xef\xe3\x12\xbd\xfa"\xb2\xb8\xa9\x94\n\x05\xfe2\xf3\xe7\xc5kD\x19\xf90\x90;[\x197\xba\x13\xd2\xbch\x03\x99X\xc9a\xc07O\xea\xd0\x80\xc1\x9d\xd3\t\x15\xe9\xcc\xeb\xed\x07\x19\x19\x9d\x80\x11g\xff\x85\xfe\xa1\x0b4\xb8m\x03h\x80%\xaa\x85\\7\xf3\x80\xbc\xb9\xca\xde\xdd6C\xc23\x02C\xe2\xe5a\xb2K\x80\xc0\xe1\x15\xde"\xee\x1f\x83\x1f\xda\x80\x1e\xc5BOq\xef\x80\xa8\xd5\xfd%0\xb5\x80\x80\x84VL!V\x80\x1a>',
               b'\xfb\xea\xcd\xf3\xdd\x80K\xbcG\x0b\x80\x1f\xe9Z\x95\xc5:2\xce\xd7\t\xbe.\x80\xb8+\xe5\x023<\x02/7u\xfa\x03X\xea\x15\x03\xaa;\x0e0\xccD\x12\xa6\x01\x12c\xb8\x80\xf9\xc6]\xee\xcd\xe5q\xc4\xc03T\x1a\xcc\r\xfe\xd0\xe9\x07\xd0\xf1)\xad\xbe\x84\x90\x13\xdf\xa1\x13\xde\x06\xc1q\x1d\x0f\xf5!\x84CC\t\x17\xb1\x19\xf3\xdfq\xdd\x90O\xacc\xb56:\x02\xd3\x80\x05\xb1\xea\xe7\x05\xed\xcc\x1f\x03\xe9\r\xef\x9d}\x16B\xf1\x808\x99\xd24\x95*\xees\x80\x16\xca\x80[\x0b\xc5\x80\xed\xb0\xbd\xb2\x064[\xe9J\x034\xd9\xd2a\xa4|\x80\xce\xfe\n\xdd\xf3\xe6%\x9c\x06\xcd\x80.\xf2aJ}\n\x83\xd1\x05\xf3P.\xa9w\x80\xaeF\x80K\x1a\x80.&',
               b'\xac!\x80\x07\x01\xd6\x80\x17h*\x806\x9d<\x1d\xfa\xb2\xa1\xe2\x80\x9f\x80C\xac\xc4e\xf2\xae\xe1\x12\x90/\xeb\xc2\xb9\x00C)R\xb1\xba+.\x9f\xbdH&\x00\x1f\xd6c\x80\xa1\xd1\x05\x19\t\x02Jm\xbe\xc6\'m\xd37\x80*\xf9\xae\xe5\xc6\x06[\xe1F\xe3\xa8\xe94\x00S\x12\xd0\xdf\xda@.\r\xfe\xb5\\\x1a\xee6-4T\xe1D>\xb64\x17#\xe3\xf5t\x9f\xeeL\x1e\x07\xd2:\x1e\xf1\xc0\x1bC\'\xe3\xed\xc9@\xf7\x80&\xbd\xed\n\x1aW\xcd\r\n\x0f\xccZ\xfa\xf5\x1f\xa6%0\x93\xb1\x95\xc8\xf1}[\x00\nD\xe2\xb2\xcd@\x13@"\xba\xfe\xdd\xdb#P@\xd9Z\x80\x90\x1d\xc8\r\x1b@8\x95\x80\xde\xdbJK\xc5\x80O\x00.*B\r\xc6\xcd\x19',
               b'\xae\x1a\x80\xf9\xeb\xe7\x9c\xfei/h\x16\xb1\x1e.\xf3\xc0\x9c\xe9\x80\xba\xb8C\xa5\xc8K\n\xe3\xef\x19\xa96\x11\xc9\x19\x13OL-\x90\xeb7P\x9c\xa5/0\x1f\r\x12W\x80\xa3\xd9\xf9\x02\x03\x12\x11w\xad\xbaK\x80\xfb\x07\x80+\xfd\x95\xe9\xda\xd0q\xc2\x12\xf7\xa4\xf7/\xe2\x80\xf2\xce\xfa\x0fJ"\x1e\x15\x904\xfa\xe9V\x11\xf6p\xd7\x80G\xa6C\xfd)\xf2\'i\xba\tN\x11\xda\xf3*\x1a\x94\xb4\xfee\x17\x11\x01\xc9;\x03u%\xc1\xe2\xf3*\x80\xa6\x1d0\x07\xbdC\xc9\xc8:\xa8\x07!\xc1\xca\xb8\x97\xdf\x80i\xcd\xfb%\xdf\xc6\xe7C\xc20\x12\xae\xe7\xf2\x02\x0f2]\x02@\x80\xbc/\xd6\xf3\xee-\x0b\x83\x93\xfd\xdd&\x80\xbdRO\xd7\x1f\x15\x0e\xe6\xba\xdb\x1f',
               b'\xd3\xfb\xbd\x1d]\xc9\x80-`:\x80\xe5\xbe\xee:\x06\xea\xd2%\x80\xb0\xca\x17\xe3\x01P\xff\xd9\'\xdd\xae\x0f\x1d\xf1\x07-.P/\xa4\r\'V\xd5\xb4\xf2\'C\xe6\xe5\x11\x80\xce\xed\xfe\xe3\x13\x15\x176\xcd\xf7\x16;\xda6.)%\xc6\xfb\x19\xf1#\xff7\t\x95\t7\x010*\xe3\xcc\xf3\x13S\xfe\xe9\xbd\x01\xe6\x1fF%\xf3:\xef\'K\xe9\x13\xf3\xfb\xf2\xf7q\xca\xd5\x13\xf1/\xe9\x19\xe7\xbd\xdd\x15P\x1b/\xc5\xc4@\xe1t*\xd5\xff\xf9\x0f\x11\xa8%\x1f\xf7\xff!\xef\xd6\xe3\xb4\x13"\xc2\xee\x8d\xb6\xdbPD\xf6\xeb/\xaa\xf9\xf32\xeb\'\x0f\xe3\x12%\xf3\xf6\x1b\x1b\x12*\xae\xdbB\xf9\x19\xf1\n<\x83\xe3\xd23\xf5D\xda`\x7f\x0b\xce\r\xff\xfa\x99\xc8\xf2',
               b'\x80\xa3\xe1\xf98K\x12\xfa\x16\x80\x80\xcc\xe9\t\x80\x11\xea\xd77s\x0e\xbe);\x800\x83\x1f\x03H\xc5\'\xaaT\\\r\x80*\xef\x80\xa5!TN\xe9\x05-\xa0\xbcd\xf2\x80\xf6\x80;\x1d\x00\x80\xdb\x19\x80\xad\xde\xe3\'\xdf\xe5\xea\x80\x07]\x1a\xc2\x80\x9f\xbe\x00\n\xe1\xcd\xe6T\xe6\x9d\'|\xf3\xe9\xc5\r\x80\r\xeddg\'\xa9\xda\xd93\x80\xf5%\x1eD\xfeu\xf9\x06\x91\xd1\x1e0\xc6\xaa\x97\xe7\xfa_\xfb\x194\xac\xa16#:\x80+\xb4\xa9\x05\x1f\xb5ma"\xeet\x9b\xc9H\xd1\n\x0f\xe3\x12\x91\x80&\xe3\xfbO"\xd3\x80+\x00\t\xbcON\xf7\xa1\xf6\xbd\'\xe5\xc2\x00Z6\xad+\n\xe9\x16J#%\xf3\xe3\xc1|KBxe\x1a\x80\x1e\xc0\xf1\xd6;\xfb',
               b'\xb4\xb1\xc5\xfa\x01\xc4"\x0f\x11\x80K\xfd\xc5\t;\xa9\xbd\xd3"\x1a\xff\x803\xf2\xba\n\x80\xf7\xcd\\\xeb8\x11cV\x11\x80+\xea\xc0\xda\xfb\x0e\x0f#\'\xe9\xae\x05u\xfa\xc4\xa1\x80B&\xe7\xdf\xc5\xe1\x80\xea\xb4\x1f\'\xd7\'\x19d\xeb3\x11\xeb\x8c\xca\xf9\xbe\x07\x13\xb6\x1aK\xb9\xe2\xcc\x80\n\xfd\xc0\xce\x80\x07\x1e}P\xcc\xe93\xe2\x05D\'\xdb\x1bH\r\x7f\xd6\xcc\xc2\xe6\xf1-\xd6\xc4\xb0\x12\xb8i\xc8\xf9\x03\xc4\xc1&\x15J\x80-\x90\x94\x0e-\xfdo/X\xd2#\xbe\xbcN\xe1\x19;\xb9\xf3\xc9\x80\r\x01\tK\n\xf1\x800\xde-\xf6>L\x0f\xbeF\xf9\x1e\t\xc0\xbc\x0f\xe6\xe2F\x03\x06Xc\x1d.\xc6\x0e\x98\x80*\x19\x80\x1f;\xdei\x83\xca\xa1p\xc6',
               b"\xae\xe2\xdd\x0bT\xb9\xd6\xea\xf6}3\xe1\xe6\xff&\xd3\xc8\xf3-\x80\xdf\x99V\xea\xa9\t\x80\xf7\xed<\xe1\x1b\xda8N\xf5\x80a\xfe\xc8\xd68\x06\n\xdb\x1e\xcc\xa0\xde[\x1d\x8f\xbe\x80'\x16\x03\xf2\x93\xf7\x89\xf5\xdf[6\xca\x1d2y\x064\x1b\xda\xc4\x8f\xda\xbc\x1e\r\x95\x16L\xee\xb2\x07H\xe7\xee\xae\xe9\x80+\xf7]L\x1d\xe2\x12\xde'H\xf2\xf1\x1ecG@\r\xd6\xdf\x9f\xfb\x0b\xd7\xc1\xa6\xe3\xf9#\xf3\x1d\xfa\xb8\x95!<T\xb62\xcd\xa373\xf6:p6\x13\x1f\x89\xbdT\xfa\x19\x11\xc9'\xa9\x80\x17\xce\x0f<\xdb\xe7\x9d?\xe7'\xce6\x15\xc5\xa0\xe7\xf9\r8\xd3\xc9&\x0b\xf33\xcc\xf64V\x0b'\xd9\x12\x97\x80a+\x80\x1f)\xc1D\x80\xdb\xad0\xc8"]
names = ['LSB', 'LSB', 'LSB', 'QZH', 'QZH','QZH', 'ZPZ', 'ZPZ', 'ZPZ', 'Mr.10']
#******************人脸相似度********************
ACCURACY = 75

while (1):
    #**************************串口屏串口接收**********************
    read_data1 =str(uart_A.read())
    #print(read_data1)
    if(read_data1!='None'):
      print(read_data1)
      if(read_data1[2:3]=='1'):
        j_1=1
        if(j_2==1):
          uart_B.write('a'+'\r''\n')
        if(j_2==0):    
          #uart_B.write('!'+'\r''\n')
          uart_B.write(read_data1[3:5]+'\r''\n')
        j_2=0  
      if(read_data1[2:3]=='2'):
        j_1=2
        uart_B.write("4"+'\r''\n')
      if(read_data1[2:3]=='3'):
        j_1=3
        Z_1=0
        uart_B.write("0"+'\r''\n')
      if(read_data1[2:3]=='4'):
        record_ftrs = []
                
        j_1=3
        Z_1=1
        uart_B.write("7"+'\r''\n')
      if(read_data1[2:3]=='5'):#保留特征值
        record_ftrs = [b'\xd9\xfe\xd3\xe2\xea\x80>\xddJ8\\\x12\x0fO\xc2\xe1`L\t\xce\xea\xa9/\x80\xc2<\xcc\xe6\x15\x12\x02\x15/\\\xe5\xe6[\xffS\x12\xb5V\x15.\xc4P\x1e\xb9!\x17a\xaa\x80\xdd\xc8g\xe5\xe6\xe3F\xc6\xe37P*\xbd#\xee\xf9\x11\x06\xc9\xfe\x11\xb0\xc9\x95\xa8\x06\xf2\xd0\x0f\x9f\t\xe5\x80\x02\x1f\xd2\x11\x9dLP\x12H\xd0\x1b\xff\xf1g\xfa\x9ds\xd1T\xf2)C\xdf\xd9k\x03\xd0\xda\xfb"\xf3\xdb\xff\x0b\x07\x02\x1d\xa1\x80\tN\xce\x80\x15\xc9\xdf;\xd1`\x0ep\x80\x1b\xbe\x80X\x03\x02\x80\xc2\xdd\xea\xdd\xca@B\xde!\x01/\xf9\xce+\xc1g\x80\xa4\xee\xf1\xa8\x15\xe5"\x8c\x15\xfb\x80)\xebO8\x80\xf5\x91\xb1\xde\xf3D\x15\xda\x80\x80\x99Pa2&\x80!3',
                     b'\xd0\xf7\xc5\xe1\n\x80C\xd5-7\x80S\xedZ\xcc\xc9<\x19\xed\xf6\xea\xbd\x16\x80\xb5D\xf1\xfd\x1d/\xf5C&\x80\x0e\ni\xf9#\xf9\xd2.\x1fN\xb1?\r\x89!\r\x7f\xaa\x80\xbd\xad:\xbe\xf3\xf3R\xc2\xeb@}3\xb1\x0f\x01\xef\xe3\x12\xbd\xfa"\xb2\xb8\xa9\x94\n\x05\xfe2\xf3\xe7\xc5kD\x19\xf90\x90;[\x197\xba\x13\xd2\xbch\x03\x99X\xc9a\xc07O\xea\xd0\x80\xc1\x9d\xd3\t\x15\xe9\xcc\xeb\xed\x07\x19\x19\x9d\x80\x11g\xff\x85\xfe\xa1\x0b4\xb8m\x03h\x80%\xaa\x85\\7\xf3\x80\xbc\xb9\xca\xde\xdd6C\xc23\x02C\xe2\xe5a\xb2K\x80\xc0\xe1\x15\xde"\xee\x1f\x83\x1f\xda\x80\x1e\xc5BOq\xef\x80\xa8\xd5\xfd%0\xb5\x80\x80\x84VL!V\x80\x1a>',
                     b'\xfb\xea\xcd\xf3\xdd\x80K\xbcG\x0b\x80\x1f\xe9Z\x95\xc5:2\xce\xd7\t\xbe.\x80\xb8+\xe5\x023<\x02/7u\xfa\x03X\xea\x15\x03\xaa;\x0e0\xccD\x12\xa6\x01\x12c\xb8\x80\xf9\xc6]\xee\xcd\xe5q\xc4\xc03T\x1a\xcc\r\xfe\xd0\xe9\x07\xd0\xf1)\xad\xbe\x84\x90\x13\xdf\xa1\x13\xde\x06\xc1q\x1d\x0f\xf5!\x84CC\t\x17\xb1\x19\xf3\xdfq\xdd\x90O\xacc\xb56:\x02\xd3\x80\x05\xb1\xea\xe7\x05\xed\xcc\x1f\x03\xe9\r\xef\x9d}\x16B\xf1\x808\x99\xd24\x95*\xees\x80\x16\xca\x80[\x0b\xc5\x80\xed\xb0\xbd\xb2\x064[\xe9J\x034\xd9\xd2a\xa4|\x80\xce\xfe\n\xdd\xf3\xe6%\x9c\x06\xcd\x80.\xf2aJ}\n\x83\xd1\x05\xf3P.\xa9w\x80\xaeF\x80K\x1a\x80.&',

                     b'\xac!\x80\x07\x01\xd6\x80\x17h*\x806\x9d<\x1d\xfa\xb2\xa1\xe2\x80\x9f\x80C\xac\xc4e\xf2\xae\xe1\x12\x90/\xeb\xc2\xb9\x00C)R\xb1\xba+.\x9f\xbdH&\x00\x1f\xd6c\x80\xa1\xd1\x05\x19\t\x02Jm\xbe\xc6\'m\xd37\x80*\xf9\xae\xe5\xc6\x06[\xe1F\xe3\xa8\xe94\x00S\x12\xd0\xdf\xda@.\r\xfe\xb5\\\x1a\xee6-4T\xe1D>\xb64\x17#\xe3\xf5t\x9f\xeeL\x1e\x07\xd2:\x1e\xf1\xc0\x1bC\'\xe3\xed\xc9@\xf7\x80&\xbd\xed\n\x1aW\xcd\r\n\x0f\xccZ\xfa\xf5\x1f\xa6%0\x93\xb1\x95\xc8\xf1}[\x00\nD\xe2\xb2\xcd@\x13@"\xba\xfe\xdd\xdb#P@\xd9Z\x80\x90\x1d\xc8\r\x1b@8\x95\x80\xde\xdbJK\xc5\x80O\x00.*B\r\xc6\xcd\x19',
                     b'\xae\x1a\x80\xf9\xeb\xe7\x9c\xfei/h\x16\xb1\x1e.\xf3\xc0\x9c\xe9\x80\xba\xb8C\xa5\xc8K\n\xe3\xef\x19\xa96\x11\xc9\x19\x13OL-\x90\xeb7P\x9c\xa5/0\x1f\r\x12W\x80\xa3\xd9\xf9\x02\x03\x12\x11w\xad\xbaK\x80\xfb\x07\x80+\xfd\x95\xe9\xda\xd0q\xc2\x12\xf7\xa4\xf7/\xe2\x80\xf2\xce\xfa\x0fJ"\x1e\x15\x904\xfa\xe9V\x11\xf6p\xd7\x80G\xa6C\xfd)\xf2\'i\xba\tN\x11\xda\xf3*\x1a\x94\xb4\xfee\x17\x11\x01\xc9;\x03u%\xc1\xe2\xf3*\x80\xa6\x1d0\x07\xbdC\xc9\xc8:\xa8\x07!\xc1\xca\xb8\x97\xdf\x80i\xcd\xfb%\xdf\xc6\xe7C\xc20\x12\xae\xe7\xf2\x02\x0f2]\x02@\x80\xbc/\xd6\xf3\xee-\x0b\x83\x93\xfd\xdd&\x80\xbdRO\xd7\x1f\x15\x0e\xe6\xba\xdb\x1f',
                     b'\xd3\xfb\xbd\x1d]\xc9\x80-`:\x80\xe5\xbe\xee:\x06\xea\xd2%\x80\xb0\xca\x17\xe3\x01P\xff\xd9\'\xdd\xae\x0f\x1d\xf1\x07-.P/\xa4\r\'V\xd5\xb4\xf2\'C\xe6\xe5\x11\x80\xce\xed\xfe\xe3\x13\x15\x176\xcd\xf7\x16;\xda6.)%\xc6\xfb\x19\xf1#\xff7\t\x95\t7\x010*\xe3\xcc\xf3\x13S\xfe\xe9\xbd\x01\xe6\x1fF%\xf3:\xef\'K\xe9\x13\xf3\xfb\xf2\xf7q\xca\xd5\x13\xf1/\xe9\x19\xe7\xbd\xdd\x15P\x1b/\xc5\xc4@\xe1t*\xd5\xff\xf9\x0f\x11\xa8%\x1f\xf7\xff!\xef\xd6\xe3\xb4\x13"\xc2\xee\x8d\xb6\xdbPD\xf6\xeb/\xaa\xf9\xf32\xeb\'\x0f\xe3\x12%\xf3\xf6\x1b\x1b\x12*\xae\xdbB\xf9\x19\xf1\n<\x83\xe3\xd23\xf5D\xda`\x7f\x0b\xce\r\xff\xfa\x99\xc8\xf2',
                     b'\x80\xa3\xe1\xf98K\x12\xfa\x16\x80\x80\xcc\xe9\t\x80\x11\xea\xd77s\x0e\xbe);\x800\x83\x1f\x03H\xc5\'\xaaT\\\r\x80*\xef\x80\xa5!TN\xe9\x05-\xa0\xbcd\xf2\x80\xf6\x80;\x1d\x00\x80\xdb\x19\x80\xad\xde\xe3\'\xdf\xe5\xea\x80\x07]\x1a\xc2\x80\x9f\xbe\x00\n\xe1\xcd\xe6T\xe6\x9d\'|\xf3\xe9\xc5\r\x80\r\xeddg\'\xa9\xda\xd93\x80\xf5%\x1eD\xfeu\xf9\x06\x91\xd1\x1e0\xc6\xaa\x97\xe7\xfa_\xfb\x194\xac\xa16#:\x80+\xb4\xa9\x05\x1f\xb5ma"\xeet\x9b\xc9H\xd1\n\x0f\xe3\x12\x91\x80&\xe3\xfbO"\xd3\x80+\x00\t\xbcON\xf7\xa1\xf6\xbd\'\xe5\xc2\x00Z6\xad+\n\xe9\x16J#%\xf3\xe3\xc1|KBxe\x1a\x80\x1e\xc0\xf1\xd6;\xfb',
                     b'\xb4\xb1\xc5\xfa\x01\xc4"\x0f\x11\x80K\xfd\xc5\t;\xa9\xbd\xd3"\x1a\xff\x803\xf2\xba\n\x80\xf7\xcd\\\xeb8\x11cV\x11\x80+\xea\xc0\xda\xfb\x0e\x0f#\'\xe9\xae\x05u\xfa\xc4\xa1\x80B&\xe7\xdf\xc5\xe1\x80\xea\xb4\x1f\'\xd7\'\x19d\xeb3\x11\xeb\x8c\xca\xf9\xbe\x07\x13\xb6\x1aK\xb9\xe2\xcc\x80\n\xfd\xc0\xce\x80\x07\x1e}P\xcc\xe93\xe2\x05D\'\xdb\x1bH\r\x7f\xd6\xcc\xc2\xe6\xf1-\xd6\xc4\xb0\x12\xb8i\xc8\xf9\x03\xc4\xc1&\x15J\x80-\x90\x94\x0e-\xfdo/X\xd2#\xbe\xbcN\xe1\x19;\xb9\xf3\xc9\x80\r\x01\tK\n\xf1\x800\xde-\xf6>L\x0f\xbeF\xf9\x1e\t\xc0\xbc\x0f\xe6\xe2F\x03\x06Xc\x1d.\xc6\x0e\x98\x80*\x19\x80\x1f;\xdei\x83\xca\xa1p\xc6',
                     b"\xae\xe2\xdd\x0bT\xb9\xd6\xea\xf6}3\xe1\xe6\xff&\xd3\xc8\xf3-\x80\xdf\x99V\xea\xa9\t\x80\xf7\xed<\xe1\x1b\xda8N\xf5\x80a\xfe\xc8\xd68\x06\n\xdb\x1e\xcc\xa0\xde[\x1d\x8f\xbe\x80'\x16\x03\xf2\x93\xf7\x89\xf5\xdf[6\xca\x1d2y\x064\x1b\xda\xc4\x8f\xda\xbc\x1e\r\x95\x16L\xee\xb2\x07H\xe7\xee\xae\xe9\x80+\xf7]L\x1d\xe2\x12\xde'H\xf2\xf1\x1ecG@\r\xd6\xdf\x9f\xfb\x0b\xd7\xc1\xa6\xe3\xf9#\xf3\x1d\xfa\xb8\x95!<T\xb62\xcd\xa373\xf6:p6\x13\x1f\x89\xbdT\xfa\x19\x11\xc9'\xa9\x80\x17\xce\x0f<\xdb\xe7\x9d?\xe7'\xce6\x15\xc5\xa0\xe7\xf9\r8\xd3\xc9&\x0b\xf33\xcc\xf64V\x0b'\xd9\x12\x97\x80a+\x80\x1f)\xc1D\x80\xdb\xad0\xc8"]
        print("待选择")
        j_1=0
        j_2=1
    #********************32接收***********************    
    read_data2 =str(uart_B.read())
    #print(read_data2)
    if(read_data2!='None'):
      print(read_data2[7:9])

      uart_A.write("n0.val="+str(read_data2[7:9]))
      uart_A.write(data)
      #print(read_data2)
    img = sensor.snapshot()
    clock.tick()
    code = kpu.run_yolo2(task, img)
    if code:
        totalRes = len(code)

        for item in code:
            ##******************图片转换********************
            a = img.draw_rectangle(item.rect())
            face_cut = img.cut(item.x(), item.y(), item.w(), item.h())
            face_cut_128 = face_cut.resize(128, 128)
            a = face_cut_128.pix_to_ai()
            if(j_1==0 or j_1==1):
              del (face_cut_128)
              del (face_cut)
            #******************口罩********************
            if(j_1==2):
              confidence = float(item.value())
              itemROL = item.rect()
              classID = int(item.classid())
              if confidence < 0.52:
                  _ = img.draw_rectangle(itemROL, color=color_B, tickness=5)
                  continue
  
              if classID == 1 and confidence > 0.65:
                  _ = img.draw_rectangle(itemROL, color_G, tickness=5)
                  if totalRes == 1:
                      drawConfidenceText(img, (0, 0), 1, confidence)
              else:
                  _ = img.draw_rectangle(itemROL, color=color_R, tickness=5)
                  if totalRes == 1:
                      drawConfidenceText(img, (0, 0), 0, confidence)
              del (face_cut_128)
            #******************人脸********************
            if(j_1==3):
              fmap = kpu.forward(task_fe, face_cut_128)
              feature = kpu.face_encode(fmap[:])
              reg_flag = False
              scores = []
              for j in range(len(record_ftrs)):
                  score = kpu.face_compare(record_ftrs[j], feature)
                  scores.append(score)
              max_score = 0
              index = 0
              del (face_cut_128)
              for k in range(len(scores)):
                  if max_score < scores[k]:
                      max_score = scores[k]
                      index = k
              if max_score > ACCURACY:
                  a = img.draw_string(item.x(), item.y(), ("%s :%2.1f" % (
                      names[index], max_score)), color=(0, 255, 0), scale=2)
  
                  if(index==0 or index==1 or index==2):
                    #print("zaima")
                    B_1=B_1+1
                    B_2=B_3=B_4=0
                    if(B_1==20):
                      #print("识别到了:" ,index)
                      uart_A.write("n0.val=1")
                      uart_A.write(data)
                      if(Z_1==0  ):
                        uart_B.write("1"+'\r''\n')
                        print("啊啊啊啊啊啊")
                      if(Z_1==1):
                        uart_B.write("9"+'\r''\n')
                      B_1=0
                  if(index==3 or index==4 or index==5):
                    B_2=B_2+1
                    B_1=B_3=B_4=0
                    if(B_2==20):
                      print("识别到了:" ,index)
                      uart_A.write("n0.val=2")
                      uart_A.write(data)
                      uart_B.write("2"+'\r''\n')
                      B_2=0
                  if(index==6 or index==7 or index==8):
                    B_3=B_3+1
                    B_1=B_2=B_4=0
                    if(B_3==20):
                      print("识别到了:" ,index)
                      uart_A.write("n0.val=3")
                      uart_A.write(data)
                      uart_B.write("3"+'\r''\n')
                      B_3=0
                  #print("识别到了:" ,index)    
              else:
                  a = img.draw_string(item.x(), item.y(), ("X :%2.1f" % (
                  max_score)), color=(255, 0, 0), scale=2)
                  B_4=B_4+1
                  if(B_4==10):
                    print("未注册")
                    uart_A.write("n0.val=4")
                    uart_A.write(data)
                    if(Z_1==0):
                      uart_B.write("#"+'\r''\n')
                      print("啊啊啊啊啊啊")
                    if(j_4==1):
                      uart_B.write("&&"+'\r''\n')
                    
                    B_4=0
              #***********************按键注册*******************        
              if start_processing:
                  record_ftrs = []
                  record_ftr = feature
                  record_ftrs.append(record_ftr)
                  uart_B.write("8"+'\r''\n')
                  j_4=1
                  print(feature)
                  start_processing = False
              break
    fps = clock.fps()
    #print("%2.1f fps" % fps)
    img.draw_string(0, 200, "%2.1f fps" % fps, scale=2, color=(255, 0, 0))
    a = lcd.display(img)
    gc.collect()
    b= img.draw_rectangle(80,22,159,195)
  • 4
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值