当前位置:网站首页>K210门禁毕设

K210门禁毕设

2022-07-01 00:37:00 Mrli0530

1.测温


#=======================测温=====================#
from machine import I2C
import time
i2c = I2C(I2C.I2C0,freq=100000, scl=0, sda=1)
time.sleep_ms(100)

MLX90614_IIC_ADDR	= const(0x5A)
MLX90614_TA			= const(0x06)
MLX90614_TOBJ1 		= const(0x07)
temp=0
class MLX90614:
  def __init__(self,i2c,addr=MLX90614_IIC_ADDR):
    self.addr=addr
    self.i2c=i2c

  def getObjCelsius(self):
        return self.getTemp(MLX90614_TOBJ1)	#Get celsius temperature of the object

  def getEnvCelsius(self):
        return self.getTemp(MLX90614_TA)	#Get celsius temperature of the ambient

  def getObjFahrenheit(self):
        return (self.getTemp(MLX90614_TOBJ1) * 9 / 5) + 32	#Get fahrenheit temperature of the object

  def getEnvFahrenheit(self):
        return (self.getTemp(MLX90614_TA) * 9 / 5) + 32	#Get fahrenheit temperature of the ambient


  def getTemp(self,reg):
        global temp
        temp = self.getReg(reg)*0.02-273.15	#Temperature conversion
        
        

  def getReg(self,reg):
    data = self.i2c.readfrom_mem(self.addr,reg,3) 							#Receive DATA
    result = (data[1]<<8) | data[0]
    return result
ir = MLX90614(i2c)


while (1):
    ir.getObjCelsius()
    print("temp %s *C"% (temp))    

2.语音

import time
from fpioa_manager import fm
from machine import UART
#*************************串口1参数*******************************
fm.register(2, fm.fpioa.UART1_TX, force=True)
fm.register(33, fm.fpioa.UART1_RX, force=True)
uart_1 = UART(UART.UART1, 9600, 8, 0, 0, timeout=1000, read_buf_len=4096)
#******语音播报GB2312******#
a_1 = [0xBB,0xB6,0xD3,0xAD,0xCA,0xB9,0xD3,0xC3,0xBB,0xF9,0xD3,0xDA,0x4B,0x32,0x31,0x30,0xB5,0xC4,0xD6,0xC7,0xC4,0xDC,0xC3,0xC5,0xCE,0xC0,0xCF,0xB5,0xCD,0xB3,0x00]#开场词
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]#请佩戴口罩
a_3 = [0xD2,0xD1,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x20,0x20,0xC7,0xEB,0xBD,0xAB,0xC8,0xCB,0xCC,0xE5,0xCA,0xD6,0xCD,0xF3,0xB4,0xA6,0xD6,0xC3,0xD3,0xDA,0xB2,0xE2,0xCE,0xC2,0xB1,0xEA,0xD6,0xBE,0xB4,0xA6,0xB2,0xE2,0xCE,0xC2,0x00]#已佩口罩 请将人体手腕处置于测温标志处测温
a_4 = [0xCC,0xE5,0xCE,0xC2,0xD5,0xFD,0xB3,0xA3,0x00]#体温正常
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]#摄氏度
a_6 = [0xC7,0xEB,0xD4,0xDA,0x36,0x30,0xC3,0xEB,0xC4,0xDA,0xB7,0xC5,0xD6,0xC3,0xBD,0xA1,0xBF,0xB5,0xC2,0xEB,0xB5,0xBD,0xD6,0xB8,0xCA,0xBE,0xCE,0xBB,0xD6,0xC3,0x00]#请在60秒内放置健康码到指示位置
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]#绿码请通行
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]#黄码
a_9 = [0xBA,0xEC,0xC2,0xEB,0xCE,0xA3,0xCF,0xD5,0xC7,0xEB,0xB5,0xC8,0xB4,0xFD,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xB4,0xA6,0xC0,0xED,0x00]#红码危险请等待工作人员处理
a_10 = [0xCC,0xE5,0xCE,0xC2,0xD2,0xEC,0xB3,0xA3,0xC7,0xEB,0xC1,0xAA,0xCF,0xB5,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xBA,0xCB,0xCA,0xB5,0x00]#体温异常
b_1=0

def yuyin():
    global b_1
    if b_1==0:
      uart_1.write(bytes(a_10))
      b_1=1
while(1):
#*********发送***********#
    yuyin()

3.红外人体检测

低电平有效

from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(3,fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0,GPIO.IN)
while 1:
  print(key.value())

4.健康码检测

1.正规写法

import sensor, image

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # can be QVGA on M7...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
while(True):
    img = sensor.snapshot()
    img.lens_corr(1.6) # strength of 1.8 is good for the 2.8mm lens.
    for code in img.find_qrcodes():
        statistics=img.get_statistics(roi=code.rect())
        img.draw_rectangle(code.rect())
        color_l=statistics.l_mean()
        color_a=statistics.a_mean()
        color_b=statistics.b_mean()
        #print(color_l,color_a,color_b)
        if color_a<0:
            print("绿色码")
        if color_a>15:
            print("红色码")
        if 5<color_a<15:
            print("黄色码")
        #print(color_l)

2.实际用的

import sensor,image,lcd,time
import KPU as kpu

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(1)
sensor.run(1)
clock = time.clock()
classes = ['A', 'B', 'C']
task = kpu.load(0x400000)
#task = kpu.load("/sd/m.kmodel")
anchor = (2.5542, 2.6313, 3.2321, 3.2009, 3.3906, 3.4375, 3.5714, 3.6629, 3.5937, 3.9844)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
while(True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    print(clock.fps())
    if code:
        for i in code:
            a=img.draw_rectangle(i.rect())
            img.draw_string(i.x(), i.y()-12, classes[i.classid()])
            img.draw_string(i.x(), i.y()+12, '%.3f'%i.value())
            a = lcd.display(img)

    else:
        a = lcd.display(img)
a = kpu.deinit(task)

5.口罩

import sensor, image, lcd, time
import KPU as kpu

color_R = (255, 0, 0)
color_G = (0, 255, 0)
color_B = (0, 0, 255)


class_IDs = ['no_mask', 'mask']


def drawConfidenceText(image, rol, classid, value):
    text = ""
    _confidence = int(value * 100)

    if classid == 1:
        text = 'mask: ' + str(_confidence) + '%'
    else:
        text = 'no_mask: ' + str(_confidence) + '%'

    image.draw_string(rol[0], rol[1], text, color=color_R, scale=2.5)



lcd.init()
sensor.reset(dual_buff=True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(1)
sensor.run(1)


task = kpu.load(0x300000)


anchor = (0.1606, 0.3562, 0.4712, 0.9568, 0.9877, 1.9108, 1.8761, 3.5310, 3.4423, 5.6823)
_ = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
img_lcd = image.Image()

clock = time.clock()
while (True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    if code:
        totalRes = len(code)

        for item in code:
            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)

    _ = lcd.display(img)

    print(clock.fps())

_ = kpu.deinit(task)


6.舵机

''' 实验名称:舵机控制(Servo Control) 版本:v1.0 日期:2019.12 作者:01Studio 【www.01Studio.org】 说明:通过编程控制舵机旋转到不同角度 '''

from machine import Timer,PWM
import time

#PWM通过定时器配置,接到IO17引脚(Pin IO17)
tim = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)
S1 = PWM(tim, freq=50, duty=0, pin=4)

''' 说明:舵机控制函数 功能:180度舵机:angle:-90至90 表示相应的角度 360连续旋转度舵机:angle:-90至90 旋转方向和速度值。 【duty】占空比值:0-100 '''

def Servo(servo,angle):
    S1.duty((angle+90)/180*10+2.5)


while True:
    #-90度
    Servo(S1,-90)
    time.sleep(1)

    #-45度
    Servo(S1,-45)
    time.sleep(1)

    #0度
    Servo(S1,0)
    time.sleep(1)

    #45度
    Servo(S1,45)
    time.sleep(1)

    #90度
    Servo(S1,90)
    time.sleep(1)

7.人体通过检测

#*******************人体通过检测*******************#
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(7,fpioa.GPIOHS1)
key = GPIO(GPIO.GPIOHS1,GPIO.IN)
while 1:
  print(key.value())

8.低功耗(假)

import lcd
import image
import time
lcd.init()
lcd.draw_string(100, 100, "hello maixpy", lcd.RED, lcd.BLACK)

time.sleep(2)
lcd.clear()
import time
from machine import Timer

def on_timer(timer):
    print("time up:",timer)
    print("param:",timer.callback_arg())

tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=5, unit=Timer.UNIT_S, callback=on_timer, arg=on_timer, start=False, priority=1, div=0)
print("period:",tim.period())
tim.start()


del tim

感觉这个还挺NB的,记录下吧,哈哈哈哈哈哈哈

import time
from machine import Timer
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(3,fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0,GPIO.IN)
a_2=0

def on_timer(timer):
    global a_2
    if a_2<30:
        a_2=a_2+1
    else:
        if key.value()==0:
            print("有人")
        else:
            print("没人")
        a_2=0
tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=1, unit=Timer.UNIT_S, callback=on_timer, arg=on_timer, start=False, priority=1, div=0)
print("period:",tim.period())
tim.start()

最终用的

from Maix import FPIOA
from Maix import GPIO
from board import board_info
from fpioa_manager import fm
def test_irq(pin_num):
    global c_2
    global c_1
    print("key", pin_num, "\n")
    c_2=0
    c_1=0
fm.register(3, fm.fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_NONE)

key.irq(test_irq, GPIO.IRQ_BOTH, GPIO.WAKEUP_NOT_SUPPORT,7)
c_1=0
c_2=0
from machine import Timer
def on_timer(timer):
    global c_1
    global c_2
    if c_1<30:
        c_1=c_1+1
    else:
        c_2=1
        c_1=0
tim1 = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=1, unit=Timer.UNIT_S, callback=on_timer, arg=on_timer, start=False, priority=1, div=0)
tim1.start()
while (1):
    if c_2==0:
		print("工作")
    else:
        print("低功耗")
        lcd.draw_string(50, 20, "low power mode")

9.K210拍照

# Untitled - By: hy - 周五 5月 20 2022

# Untitled - By: hy - 周五 5月 20 2022

import sensor, image, time,os,uos

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

i=0
while(True):
    clock.tick()
    img = sensor.snapshot()
    i=i+1
    img.save("snapshot-%d.jpg" % i) # Save Pic.
    time.sleep(1)


二、整体

1.K210


#*****************语音***********************#
from fpioa_manager import fm
from machine import UART
#*************************串口1参数*******************************
fm.register(2, fm.fpioa.UART1_TX, force=True)
fm.register(33, fm.fpioa.UART1_RX, force=True)
uart_1 = UART(UART.UART1, 9600, 8, 0, 0, timeout=1000, read_buf_len=4096)
#******语音播报GB2312******#
a_1 = [0xBB,0xB6,0xD3,0xAD,0xCA,0xB9,0xD3,0xC3,0xBB,0xF9,0xD3,0xDA,0x4B,0x32,0x31,0x30,0xB5,0xC4,0xD6,0xC7,0xC4,0xDC,0xC3,0xC5,0xCE,0xC0,0xCF,0xB5,0xCD,0xB3,0x00]#开场词
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]#请佩戴口罩
a_3 = [0xD2,0xD1,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x20,0x20,0xC7,0xEB,0xBD,0xAB,0xC8,0xCB,0xCC,0xE5,0xCA,0xD6,0xCD,0xF3,0xB4,0xA6,0xD6,0xC3,0xD3,0xDA,0xB2,0xE2,0xCE,0xC2,0xB1,0xEA,0xD6,0xBE,0xB4,0xA6,0xB2,0xE2,0xCE,0xC2,0x00]#已佩口罩 请将人体手腕处置于测温标志处测温
a_4 = [0xCC,0xE5,0xCE,0xC2,0xD5,0xFD,0xB3,0xA3,0x00]#体温正常
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]#摄氏度
a_6 = [0xC7,0xEB,0xD4,0xDA,0x36,0x30,0xC3,0xEB,0xC4,0xDA,0xB7,0xC5,0xD6,0xC3,0xBD,0xA1,0xBF,0xB5,0xC2,0xEB,0xB5,0xBD,0xD6,0xB8,0xCA,0xBE,0xCE,0xBB,0xD6,0xC3,0x00]#请在60秒内放置健康码到指示位置
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]#绿码请通行
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]#黄码
a_9 = [0xBA,0xEC,0xC2,0xEB,0xCE,0xA3,0xCF,0xD5,0xC7,0xEB,0xB5,0xC8,0xB4,0xFD,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xB4,0xA6,0xC0,0xED,0x00]#红码危险请等待工作人员处理
a_10 = [0xCC,0xE5,0xCE,0xC2,0xD2,0xEC,0xB3,0xA3,0xC7,0xEB,0xC1,0xAA,0xCF,0xB5,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xBA,0xCB,0xCA,0xB5,0x00]#体温异常
#*******************红外人体*******************#
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(3,fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0,GPIO.IN)
#*****************口罩*************************#
import sensor, image, lcd, time
import KPU as kpu

color_R = (255, 0, 0)
color_G = (0, 255, 0)
color_B = (0, 0, 255)


class_IDs = ['no_mask', 'mask']


def drawConfidenceText(image, rol, classid, value):
    text = ""
    _confidence = int(value * 100)

    if classid == 1:
        text = 'mask: ' + str(_confidence) + '%'
    else:
        text = 'no_mask: ' + str(_confidence) + '%'

    image.draw_string(rol[0], rol[1], text, color=color_R, scale=2.5)



lcd.init()
sensor.reset(dual_buff=True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(1)
sensor.run(1)


task = kpu.load(0x300000)


anchor = (0.1606, 0.3562, 0.4712, 0.9568, 0.9877, 1.9108, 1.8761, 3.5310, 3.4423, 5.6823)
_ = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
img_lcd = image.Image()
#************************健康吗**********************#
classes = ['A', 'B', 'C']
b_1=0
task1 = kpu.load(0x500000)
anchor1 = (2.5542, 2.6313, 3.2321, 3.2009, 3.3906, 3.4375, 3.5714, 3.6629, 3.5937, 3.9844)
a = kpu.init_yolo2(task1, 0.5, 0.3, 5, anchor1)
#=======================测温=====================#
from machine import I2C
import time
i2c = I2C(I2C.I2C0,freq=100000, scl=0, sda=1)
time.sleep_ms(100)

MLX90614_IIC_ADDR	= const(0x5A)
MLX90614_TA			= const(0x06)
MLX90614_TOBJ1 		= const(0x07)
temp=0
class MLX90614:
  def __init__(self,i2c,addr=MLX90614_IIC_ADDR):
    self.addr=addr
    self.i2c=i2c

  def getObjCelsius(self):
        return self.getTemp(MLX90614_TOBJ1)	#Get celsius temperature of the object

  def getEnvCelsius(self):
        return self.getTemp(MLX90614_TA)	#Get celsius temperature of the ambient

  def getObjFahrenheit(self):
        return (self.getTemp(MLX90614_TOBJ1) * 9 / 5) + 32	#Get fahrenheit temperature of the object

  def getEnvFahrenheit(self):
        return (self.getTemp(MLX90614_TA) * 9 / 5) + 32	#Get fahrenheit temperature of the ambient


  def getTemp(self,reg):
        global temp
        temp = self.getReg(reg)*0.02-273.15	#Temperature conversion

  def getReg(self,reg):
    data = self.i2c.readfrom_mem(self.addr,reg,3) 							#Receive DATA
    result = (data[1]<<8) | data[0]
    return result
ir = MLX90614(i2c)
#************变量-**********#
b_1=0
#=====================舵机===============#
from machine import Timer,PWM
tim = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)
S1 = PWM(tim, freq=50, duty=0, pin=6)
def Servo(servo,angle):
    S1.duty((angle+90)/180*10+2.5)
while (1):
    #*******体温**********#
    ir.getObjCelsius()
    print("temp %s *C"% (temp))
    #*******语音*****#
    if b_1==0:
      uart_1.write(bytes(a_10))
      b_1=1
    #*******红外*****#
    print(key.value())
    #*****舵机*****#
    Servo(S1,-90)
    time.sleep(1)
    Servo(S1,-45)

2.esp8266

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "ESP82666";//wifi账号
const char* password = "12345678";//wifi密码

WiFiUDP Udp;
unsigned int localUdpPort = 2333;  // 本地监听端口
char incomingPacket[255];  // 存储Udp客户端发过来的数据
char  replyPacket[] = "Hi there! Got the message :-)";  // 应答信息
String comdata = "";
String a_1,a_2,S;
//*********设置固定IP*************//
IPAddress local_IP(192, 168, 137, 185);
// Set your Gateway IP address
IPAddress gateway(192, 168, 137, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
void setup()
{
    
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);
  if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    
  Serial.println("STA Failed to configure");
}
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

  //启动Udp监听服务
  Udp.begin(localUdpPort);
  //打印本地ip地址,udp client端会使用到
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}


void loop()
{
    
      while (Serial.available() > 0)  
    {
    
        comdata += char(Serial.read());
        delay(2);
    }
    if (comdata.length() > 0)
    {
    
        //Serial.println(comdata);
        Udp.beginPacket("192.168.137.32", 2333);Udp.print(comdata);Udp.endPacket();
// S = comdata.charAt(0); //取对象里面的方法charAt
// a_1=comdata.substring(1);
// if(S=="A"){Udp.beginPacket("192.168.137.32", 2333);Udp.print(a_1);Udp.endPacket();}
// if(S=="B"){Udp.beginPacket("192.168.137.32", 2334);Udp.print(a_1);Udp.endPacket();}
// if(S=="C"){Udp.beginPacket("192.168.137.32", 2335);Udp.print(a_1);Udp.endPacket();}
// if(S=="D"){Udp.beginPacket("192.168.137.32", 2336);Udp.print(a_1);Udp.endPacket();}
// if(S=="E"){Udp.beginPacket("192.168.137.32", 2337);Udp.print(a_1);Udp.endPacket();}
        comdata = "";
    }
  //解析Udp数据包
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    
    // 收到Udp数据包
    //Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
    // 读取Udp数据包
    int len = Udp.read(incomingPacket, 255);
    if (len > 0)
    {
    
      incomingPacket[len] = 0;
    }
    //向串口调试器打印信息
    Serial.println(String(incomingPacket));

    //往udp 远端发送应答信息

  }
}

1.

#*****************语音**************************#B
from fpioa_manager import fm
from machine import UART
fm.register(2, fm.fpioa.UART1_TX, force=True)
fm.register(33, fm.fpioa.UART1_RX, force=True)
uart_1 = UART(UART.UART1, 9600, 8, 0, 0, timeout=1000, read_buf_len=4096)
b_1=0
#**********语音播报GB2312******#
a_1 = [0xBB,0xB6,0xD3,0xAD,0xCA,0xB9,0xD3,0xC3,0xBB,0xF9,0xD3,0xDA,0x4B,0x32,0x31,0x30,0xB5,0xC4,0xD6,0xC7,0xC4,0xDC,0xC3,0xC5,0xCE,0xC0,0xCF,0xB5,0xCD,0xB3,0x00]#开场词
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]#请佩戴口罩
a_3 = [0xD2,0xD1,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x20,0x20,0xC7,0xEB,0xBD,0xAB,0xC8,0xCB,0xCC,0xE5,0xCA,0xD6,0xCD,0xF3,0xB4,0xA6,0xD6,0xC3,0xD3,0xDA,0xB2,0xE2,0xCE,0xC2,0xB1,0xEA,0xD6,0xBE,0xB4,0xA6,0xB2,0xE2,0xCE,0xC2,0x00]#已佩口罩 请将人体手腕处置于测温标志处测温
a_4 = [0xCC,0xE5,0xCE,0xC2,0xD5,0xFD,0xB3,0xA3,0xC7,0xEB,0xD4,0xDA,0x36,0x30,0xC3,0xEB,0xC4,0xDA,0xB7,0xC5,0xD6,0xC3,0xBD,0xA1,0xBF,0xB5,0xC2,0xEB,0xB5,0xBD,0xD6,0xB8,0xCA,0xBE,0xCE,0xBB,0xD6,0xC3,0x00]#体温正常
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]#摄氏度
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]#绿码请通行
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]#黄码
a_9 = [0xBA,0xEC,0xC2,0xEB,0xCE,0xA3,0xCF,0xD5,0xC7,0xEB,0xB5,0xC8,0xB4,0xFD,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xB4,0xA6,0xC0,0xED,0x00]#红码危险请等待工作人员处理
a_10 =[0xCC,0xE5,0xCE,0xC2,0xD2,0xEC,0xB3,0xA3,0xC7,0xEB,0xC1,0xAA,0xCF,0xB5,0xB9,0xA4,0xD7,0xF7,0xC8,0xCB,0xD4,0xB1,0xBA,0xCB,0xCA,0xB5,0x00]#体温异常
uart_1.write(bytes(a_1))
#*******************红外人体*******************#
from Maix import FPIOA
from Maix import GPIO
from board import board_info
from fpioa_manager import fm
def test_irq(pin_num):
    global c_2
    global c_1
    print("key", pin_num, "\n")
    c_2=0
    c_1=0
fm.register(3, fm.fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_NONE)
key.irq(test_irq, GPIO.IRQ_BOTH, GPIO.WAKEUP_NOT_SUPPORT,7)
#*******************人体通过检测*******************#
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(7,fpioa.GPIOHS1)
key1 = GPIO(GPIO.GPIOHS1,GPIO.IN)
#*****************口罩*************************#
import sensor, image, lcd, time
import KPU as kpu
color_R = (255, 0, 0)
color_G = (0, 255, 0)
color_B = (0, 0, 255)
class_IDs = ['no_mask', 'mask']
def drawConfidenceText(image, rol, classid, value):
    text = ""
    _confidence = int(value * 100)

    if classid == 1:
        text = 'mask: ' + str(_confidence) + '%'
    else:
        text = 'no_mask: ' + str(_confidence) + '%'

    image.draw_string(rol[0], rol[1], text, color=color_R, scale=2.5)
lcd.init()
sensor.reset(dual_buff=True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
#sensor.set_hmirror(0)
#sensor.set_vflip(0)
sensor.run(1)
lcd.rotation(2)
task = kpu.load(0x300000)
anchor = (0.1606, 0.3562, 0.4712, 0.9568, 0.9877, 1.9108, 1.8761, 3.5310, 3.4423, 5.6823)
_ = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
img_lcd = image.Image()
#==================ESP8266====================#
fm.register(34, fm.fpioa.UART2_TX, force=True)
fm.register(35, fm.fpioa.UART2_RX, force=True)
uart_2 = UART(UART.UART2, 115200, 8, 0, 0, timeout=1000, read_buf_len=4096)
def ckjs():
    global read_data1
    global r_4
    global f_1
    global f_2
    global f_3
    global SSS
    if f_1==1 and f_2==0 and f_3==0 :
        img.draw_string(0, 0, "Mode 2")
    if f_1==1 and f_2==1 and f_3==0 :
        img.draw_string(0, 0, "Mode 1")
    if f_1==0 and f_2==0 and f_3==0 :
        img.draw_string(0, 0, "Mode 3")
    read_data1 =str(uart_2.read())
    if read_data1!='None':
        print(read_data1[2:3])
        SSS=0
        if read_data1[2:3]=='a':
            r_4=1

        if read_data1[2:3]=='b':
            f_1=1
            f_2=0
            f_3=0

        if read_data1[2:3]=='c':
            f_1=1
            f_2=1
            f_3=0
            img.draw_string(0, 0, "Mode 1")
        if read_data1[2:3]=='d':
                f_1=0
                f_2=0
                f_3=0
        #uart_2.write("asd")
#**********************低功耗******************#C
c_1=0
c_2=0
from machine import Timer
def on_timer(timer):
    global c_1
    global c_2
    if c_1<60:
        c_1=c_1+1
    else:
        c_2=1
        c_1=0
tim1 = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=1, unit=Timer.UNIT_S, callback=on_timer, arg=on_timer, start=False, priority=1, div=0)
tim1.start()
#=====测温作弊检测====#
fpioa.set_function(8,fpioa.GPIOHS3)
key2 = GPIO(GPIO.GPIOHS3,GPIO.IN)
#=====================舵机===============#
from machine import Timer,PWM
tim = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)
S1 = PWM(tim, freq=50, duty=0, pin=6)
def Servo(servo,angle):
    S1.duty((angle+90)/180*10+2.5)
Servo(S1,-45)
#---------------拍照-----------------#
import os
#==============众数滤波===============H
#*******************定义变量*****************#
h_3=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
h_1=h_2=0
#*********************众数滤波********************#
def lvbo(c_1):
  global e_1
  global h_1
  global h_2
  global h_3
  global a_3
  global a_2
  global G_1
  global SSS
  if h_1<50:
    h_3[h_1]=c_1
    h_1=h_1+1
  else:
    h_2=max(h_3, default='列表为空', key=lambda v: h_3.count(v))
    print(h_2)
    #****为下次做准备****#00
    if h_2==1 and SSS==0:
        uart_1.write(bytes(a_3))
        G_1=1
        SSS=1
    if h_2==2 and SSS==0:
        uart_1.write(bytes(a_2))
        if f_2==1 and f_3==1:
            SSS=0
        #time.sleep(2)
    h_1=1
    h_3=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

#=======================测温=====================#
from machine import I2C
import time
i2c = I2C(I2C.I2C0,freq=100000, scl=0, sda=1)
time.sleep_ms(100)

MLX90614_IIC_ADDR	= const(0x5A)
MLX90614_TA			= const(0x06)
MLX90614_TOBJ1 		= const(0x07)
temp=0
class MLX90614:
  def __init__(self,i2c,addr=MLX90614_IIC_ADDR):
    self.addr=addr
    self.i2c=i2c

  def getObjCelsius(self):
        return self.getTemp(MLX90614_TOBJ1)	#Get celsius temperature of the object

  def getEnvCelsius(self):
        return self.getTemp(MLX90614_TA)	#Get celsius temperature of the ambient

  def getObjFahrenheit(self):
        return (self.getTemp(MLX90614_TOBJ1) * 9 / 5) + 32	#Get fahrenheit temperature of the object

  def getEnvFahrenheit(self):
        return (self.getTemp(MLX90614_TA) * 9 / 5) + 32	#Get fahrenheit temperature of the ambient


  def getTemp(self,reg):
        global temp
        temp = self.getReg(reg)*0.02-273.15	#Temperature conversion

  def getReg(self,reg):
  #data = self.i2c.readfrom_mem(self.addr,reg,3)
  #result = (data[1]<<8) | data[0]#Receive DATA
  #return result
    try:
        data = self.i2c.readfrom_mem(self.addr,reg,3)
        result = (data[1]<<8) | data[0]#Receive DATA
        return result
    except:
        result=0
        return result


ir = MLX90614(i2c)
def kaimen():
    global r_4
    global SSS
    Servo(S1,0)
    print("1234")
    if key1.value()==0:
        Servo(S1,-45)
        SSS=0
        time.sleep(1)
        r_4=0
#----------------整体变量-------------#FGR
#*******功能开启*******#
f_1=1#口罩
f_2=1#体温
f_3=0#二维码
f_4=0#图像储存
#*******检测结果*******#
G_1=0
G_2=0
G_3=0
#######
SSS=0#流程变量
J=0
#######
r_1=0
r_2=0
r_3=0
r_4=0
read_data1=0
while (1):

    if c_2==0:
        J=0
        #*******口罩**********#
        img = sensor.snapshot()
        ckjs()
        if f_1==0:
            if SSS==0:

                code = kpu.run_yolo2(task, img)
                if code:
                    totalRes = len(code)
                    c_1=0
                    for item in code:
                        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)
                            lvbo(1)


                            if totalRes == 1:
                                drawConfidenceText(img, (0, 0), 1, confidence)
                        else:
                            lvbo(2)
                            _ = img.draw_rectangle(itemROL, color=color_R, tickness=5)
                            if totalRes == 1:
                                drawConfidenceText(img, (0, 0), 0, confidence)
        if f_1==1:
                G_1=1
                SSS=1
        #*******体温**********#
        if f_2==0:
            if SSS==1:

                ir.getObjCelsius()
                #
                if key2.value()==0:
                    c_1=0
                    if temp==-273.15:
                        pass
                    else :
                        print("temp %s *C"% (temp))
                        img.draw_string(50, 0, "temp %s *C"% (temp))
                        _ = lcd.display(img)

                        if temp<37.3:
                            print("一直在")
                            uart_1.write(bytes(a_4))
                            time.sleep_ms(2000)
                            G_2=1
                            SSS=2
                        else:
                            uart_1.write(bytes(a_10))
                            time.sleep_ms(2000)
                            SSS=0
        if f_2==1:
            G_2=1
            SSS=2
        #*******健康码**********#
        if f_3==0:
            if SSS==2:
                for code in img.find_qrcodes():
                    print(code.payload())
                    c_1=0
                    if code.payload()=="1":
                        print("红色")
                        uart_2.write("12")
                        SSS=0
                        r_1=0
                        uart_1.write(bytes(a_9))
                        sensor.skip_frames(60)
                    if code.payload()=="2":
                        print("绿色")
                        uart_1.write(bytes(a_7))

                        r_4=1
                        sensor.skip_frames(60)
                        r_1=0
                    if code.payload()=="3":
                        print("黄色")
                        uart_2.write("12")
                        SSS=0
                        r_1=0
                        uart_1.write(bytes(a_8))
                        sensor.skip_frames(60)



        if f_3==1:
            G_3=1
            SSS=0
        if r_4==1:
            kaimen()
        _ = lcd.display(img)
    else:
        print("低功耗")
        if J==0:
            lcd.clear()
            J=1
        lcd.draw_string(150, 100, "low power mode")
a = kpu.deinit(task)#反初始化
del(img)
原网站

版权声明
本文为[Mrli0530]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mrli0530/article/details/124817034