当前位置:网站首页>K210 access control complete
K210 access control complete
2022-07-01 01:16:00 【Mrli0530】
1. Thermometry
#======================= Thermometry =====================#
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. voice
import time
from fpioa_manager import fm
from machine import UART
#************************* A serial port 1 Parameters *******************************
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)
#****** Voice Announcements 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]# Opening remarks
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]# Please wear a mask
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]# Wearing a mask Please place the wrist of the human body at the temperature measurement mark
a_4 = [0xCC,0xE5,0xCE,0xC2,0xD5,0xFD,0xB3,0xA3,0x00]# Normal temperature
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]# Centigrade
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]# Please be there. 60 Place the health code to the indicated position within seconds
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]# Green code, please
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]# Yellow code
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]# Red code danger, please wait for the staff to handle
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]# Abnormal body temperature
b_1=0
def yuyin():
global b_1
if b_1==0:
uart_1.write(bytes(a_10))
b_1=1
while(1):
#********* send out ***********#
yuyin()
3. Infrared human detection
Low level active
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. Health code detection
1. Normal writing
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(" Green code ")
if color_a>15:
print(" The red code ")
if 5<color_a<15:
print(" Yellow code ")
#print(color_l)
2. Actually
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. masks
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. The steering gear
''' Name of the experiment : Steering gear control (Servo Control) edition :v1.0 date :2019.12 author :01Studio 【www.01Studio.org】 explain : Control the steering gear to rotate to different angles by programming '''
from machine import Timer,PWM
import time
#PWM Configure by timer , Receive IO17 Pin (Pin IO17)
tim = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)
S1 = PWM(tim, freq=50, duty=0, pin=4)
''' explain : Actuator control function function :180 Steering gear :angle:-90 to 90 Indicates the corresponding angle 360 Continuous rotation steering gear :angle:-90 to 90 Rotation direction and speed values . 【duty】 Duty cycle :0-100 '''
def Servo(servo,angle):
S1.duty((angle+90)/180*10+2.5)
while True:
#-90 degree
Servo(S1,-90)
time.sleep(1)
#-45 degree
Servo(S1,-45)
time.sleep(1)
#0 degree
Servo(S1,0)
time.sleep(1)
#45 degree
Servo(S1,45)
time.sleep(1)
#90 degree
Servo(S1,90)
time.sleep(1)
7. The human body passes the test
#******************* The human body passes the test *******************#
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. low power consumption ( false )
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
I think this one is quite NB Of , Record it , Ha ha ha ha ha ha ha
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(" someone ")
else:
print(" no one ")
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()
Final use
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(" Work ")
else:
print(" low power consumption ")
lcd.draw_string(50, 20, "low power mode")
9.K210 Taking pictures
# Untitled - By: hy - Friday 5 month 20 2022
# Untitled - By: hy - Friday 5 month 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)
Two 、 whole
1.K210
#***************** voice ***********************#
from fpioa_manager import fm
from machine import UART
#************************* A serial port 1 Parameters *******************************
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)
#****** Voice Announcements 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]# Opening remarks
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]# Please wear a mask
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]# Wearing a mask Please place the wrist of the human body at the temperature measurement mark
a_4 = [0xCC,0xE5,0xCE,0xC2,0xD5,0xFD,0xB3,0xA3,0x00]# Normal temperature
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]# Centigrade
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]# Please be there. 60 Place the health code to the indicated position within seconds
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]# Green code, please
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]# Yellow code
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]# Red code danger, please wait for the staff to handle
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]# Abnormal body temperature
#******************* Infrared human body *******************#
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(3,fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0,GPIO.IN)
#***************** masks *************************#
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()
#************************ Are you healthy **********************#
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)
#======================= Thermometry =====================#
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)
#************ Variable -**********#
b_1=0
#===================== The steering gear ===============#
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):
#******* Temperature **********#
ir.getObjCelsius()
print("temp %s *C"% (temp))
#******* voice *****#
if b_1==0:
uart_1.write(bytes(a_10))
b_1=1
#******* infrared *****#
print(key.value())
#***** The steering gear *****#
Servo(S1,-90)
time.sleep(1)
Servo(S1,-45)
2.esp8266
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "ESP82666";//wifi account number
const char* password = "12345678";//wifi password
WiFiUDP Udp;
unsigned int localUdpPort = 2333; // Local listening port
char incomingPacket[255]; // Storage Udp Data sent by the client
char replyPacket[] = "Hi there! Got the message :-)"; // Answer message
String comdata = "";
String a_1,a_2,S;
//********* Setting up 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");
// start-up Udp Listener Service
Udp.begin(localUdpPort);
// Print local ip Address ,udp client The end will use
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); // Take the method in the object 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 = "";
}
// analysis Udp Data packets
int packetSize = Udp.parsePacket();
if (packetSize)
{
// received Udp Data packets
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
// Read Udp Data packets
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
// Print information to the serial debugger
Serial.println(String(incomingPacket));
// Go to udp The remote end sends a reply message
}
}
1.
#***************** voice **************************#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
#********** Voice Announcements 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]# Opening remarks
a_2 = [0xC7,0xEB,0xC5,0xE5,0xB4,0xF7,0xBF,0xDA,0xD5,0xD6,0x00]# Please wear a mask
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]# Wearing a mask Please place the wrist of the human body at the temperature measurement mark
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]# Normal temperature
a_5 = [0xC9,0xE3,0xCA,0xCF,0xB6,0xC8,0x00]# Centigrade
a_7 = [0xC2,0xCC,0xC2,0xEB,0xC7,0xEB,0xCD,0xA8,0xD0,0xD0,0x00]# Green code, please
a_8 = [0xBB,0xCA,0xC2,0xED,0xD5,0xBE,0xD5,0xE2,0xC0,0xEF,0xB1,0xF0,0xB6,0xAF,0xB0,0xC2,0x00]# Yellow code
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]# Red code danger, please wait for the staff to handle
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]# Abnormal body temperature
uart_1.write(bytes(a_1))
#******************* Infrared human body *******************#
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)
#******************* The human body passes the test *******************#
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(7,fpioa.GPIOHS1)
key1 = GPIO(GPIO.GPIOHS1,GPIO.IN)
#***************** masks *************************#
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")
#********************** low power consumption ******************#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()
#===== Temperature measurement cheating detection ====#
fpioa.set_function(8,fpioa.GPIOHS3)
key2 = GPIO(GPIO.GPIOHS3,GPIO.IN)
#===================== The steering gear ===============#
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)
#--------------- Taking pictures -----------------#
import os
#============== Mode filtering ===============H
#******************* Defining variables *****************#
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
#********************* Mode filtering ********************#
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=' The list is empty. ', key=lambda v: h_3.count(v))
print(h_2)
#**** Prepare for the next time ****#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]
#======================= Thermometry =====================#
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
#---------------- Global variables -------------#FGR
#******* Function of open *******#
f_1=1# masks
f_2=1# Temperature
f_3=0# QR code
f_4=0# Image storage
#******* detection result *******#
G_1=0
G_2=0
G_3=0
#######
SSS=0# Process variables
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
#******* masks **********#
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
#******* Temperature **********#
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(" Has been ")
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
#******* Health code **********#
if f_3==0:
if SSS==2:
for code in img.find_qrcodes():
print(code.payload())
c_1=0
if code.payload()=="1":
print(" Red ")
uart_2.write("12")
SSS=0
r_1=0
uart_1.write(bytes(a_9))
sensor.skip_frames(60)
if code.payload()=="2":
print(" green ")
uart_1.write(bytes(a_7))
r_4=1
sensor.skip_frames(60)
r_1=0
if code.payload()=="3":
print(" yellow ")
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(" low power consumption ")
if J==0:
lcd.clear()
J=1
lcd.draw_string(150, 100, "low power mode")
a = kpu.deinit(task)# Uninitialize
del(img)
边栏推荐
- 文件服务设计
- Left join displays the specified value when the left join matching data is null
- Golang treasure house recommendation
- ArrayList analysis 1-cycle, capacity expansion, version
- Win11安装redis 数据库以及redis desktop manager的下载
- Analyze the maker education path integrating the essence of discipline
- Some views on libco
- CSDN common complex formula template record
- P4 learning - Basic tunneling
- Is the public read-only field with immutable structure valid- Does using public readonly fields for immutable structs work?
猜你喜欢
Left join displays the specified value when the left join matching data is null
ESP8266 RC522
A letter to 5000 fans!
魔王冷饭||#101 魔王解惑数量多与质量;员工管理;高考志愿填报;游戏架构设计
解析创客教育实践中的智慧原理
Oracle temporary table explanation
New content violation degree determination scana bad information monitoring capability update issue 5
Mindjet mindmanager2022 mind map decompression installer tutorial
NE555 waveform generator handle tutorial NE555 internal structure (I)
Docker 部署 MySQL 8
随机推荐
PHP online confusion encryption tutorial sharing + basically no solution
機器人編程的培訓學科類原理
探索互联网时代STEAM教育创新之路
How to do the performance pressure test of "Health Code"
Cmu15445 (fall 2019) project 1 - buffer pool details
[original] PLSQL index sorting optimization
Practical shell knowledge
Detailed analysis of operators i++ and ++i in JS, i++ and ++i
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
C#生成putty格式的ppk文件(支持passphrase)
ESP8266 RC522
Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)
Set different background colors for the border and text of the button
For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
Double linked list: initialize insert delete traversal
分割链表[先取next再斩断链表防止断链]
实验八 T-sql,存储过程
关于VCTK数据集
Shift operators