当前位置:网站首页>K210工地安全帽
K210工地安全帽
2022-07-01 00:37:00 【Mrli0530】
人体佩戴安全帽检测:
1.什么都检测不到屏幕亮黄灯
2.检测到人脸但是检测不到安全帽亮红灯,蜂鸣器响
3.检测到人脸检测到安全帽亮绿灯
一、思路
1.正规思路:先用YOLO进行人脸检测(320240)之后裁剪出图像后(224224)送入另外一个YOLO进行安全帽检测,就是这个思路。
2.捷径:先用YOLO进行人脸检测(320*240)之后得到人脸上边一点点的区域值(ROI),再用颜色识别对ROI区域进行颜色识别,识别到对应颜色后就算是识别到了
,最后实际用的就是2
二、程序
1.最终采用的程序
import sensor,image,lcd,time,gc,sys
import KPU as kpu
from Maix import FPIOA
from Maix import GPIO
from machine import Timer
def lcd_show_except(e):
import uio
err_str = uio.StringIO()
sys.print_exception(e, err_str)
err_str = err_str.getvalue()
img = image.Image(size=(224,224))
img.draw_string(0, 10, err_str, scale=1, color=(0xff,0x00,0x00))
lcd.display(img)
#*********************判断********************#
a_1=a_3=0
e_1=[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]
def panduan(a_2):
global a_1
global a_3
global e_1
if a_1<25:
e_1[a_1]=a_2
a_1=a_1+1
print("正在执行滤波算法,第",a_1,"/共25次")
else:
a_3=max(e_1, default='列表为空', key=lambda v: e_1.count(v))
a_1=0
e_1=[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]
def main(model_addr=0x300000, lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False):
try:
sensor.reset()
except Exception as e:
raise Exception("sensor reset fail, please check hardware connection, or hardware damaged! err: {}".format(e))
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(sensor_hmirror)
sensor.set_vflip(sensor_vflip)
sensor.run(1)
lcd.init(type=1)
lcd.rotation(lcd_rotation)
lcd.clear(lcd.WHITE)
lcd.init(invert = 1)
anchors = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
green_threshold = (50, 82, -22, 18, 11, 70)
#*******************变量*************************#
b_1=b_2=0
a_2=a_4=0
c_1=c_2=0
d_1=d_2=d_3=0
sss=0#记录检测次数
global a_3
#*******************引脚**************************#
fpioa = FPIOA()
fpioa.set_function(0,fpioa.GPIOHS0)#蜂鸣器
led2 = GPIO(GPIO.GPIOHS0,GPIO.OUT)
led2.value(0)
try:
task = None
task = kpu.load(model_addr)
kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:[0,1], nms_value: [0, 1]
while(True):
img = sensor.snapshot()
t = time.ticks_ms()
code = kpu.run_yolo2(task, img)
t = time.ticks_ms() - t
if code:
for i in code:
a = img.draw_rectangle(i.rect())
d_1=i.x()+20
d_2=i.y()-10
d_3=i.w()-40
if d_2<=0:
d_2=1
if d_3<=0:
d_3=1
a = img.draw_rectangle(int(d_1), int(d_2), int(d_3), 10)
blobs = img.find_blobs([green_threshold],roi=(int(d_1), int(d_2), int(d_3), 10))
if blobs:
a_2=1
panduan(a_2)
else:
a_2=2
panduan(a_2)
else:
a_2=3
panduan(a_2)
#img.draw_rectangle(0, 0, 320, 240, color = (255, 255, 0),thickness = 5, fill = False)
if a_3==1:
print("检测到")
led2.value(0)
img.draw_rectangle(0, 0, 320, 240, color = (0, 255, 0),thickness = 5, fill = False)
if a_3==2:
print("未检测到")
led2.value(1)
img.draw_rectangle(0, 0, 320, 240, color = (255, 0, 0),thickness = 5, fill = False)
if a_3==3:
print("未检测到")
led2.value(0)
img.draw_rectangle(0, 0, 320, 240, color = (255,255, 0),thickness = 5, fill = False)
img.draw_string(0, 200, "t:%dms" %(t), scale=2)
lcd.display(img)
except Exception as e:
raise e
finally:
if not task is None:
kpu.deinit(task)
if __name__ == "__main__":
try:
main( model_addr=0x300000, lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False)
# main(model_addr="/sd/m.kmodel")
except Exception as e:
sys.print_exception(e)
lcd_show_except(e)
finally:
gc.collect()
2.最终采用的程序
其实这种方法可以的,数据集采集不到位而已。
import sensor,image,lcd,time
import KPU as kpu
from Maix import FPIOA
from Maix import GPIO
from machine import Timer
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
#************************神经网络******************************#
task = kpu.load(0x300000) # 你需要把模型(face.kfpkg)在闪存地址0x300000
#模型描参数
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
#初始化 yolo2 网络
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
green_threshold = (50, 82, -22, 18, 11, 70)
#*******************引脚**************************#
fpioa = FPIOA()
fpioa.set_function(11,fpioa.GPIOHS0)
led1 = GPIO(GPIO.GPIOHS0,GPIO.OUT)
led1.value(0)
fpioa.set_function(10,fpioa.GPIOHS1)#蜂鸣器
led2 = GPIO(GPIO.GPIOHS1,GPIO.OUT)
led2.value(0)
fpioa.set_function(9,fpioa.GPIOHS2)#灯
led3 = GPIO(GPIO.GPIOHS2,GPIO.OUT)
led3.value(0)
#*******************变量*************************#
b_1=b_2=0
a_1=a_2=a_3=a_4=0
c_1=c_2=0
sss=0#记录检测次数
e_1=[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]
#*********************判断********************#
def panduan(a_2):
global a_1
global a_3
global e_1
if a_1<25:
e_1[a_1]=a_2
a_1=a_1+1
print("正在执行滤波算法,第",a_1,"/共25次")
else:
a_3=max(e_1, default='列表为空', key=lambda v: e_1.count(v))
a_1=0
e_1=[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]
while(True):
img = sensor.snapshot()
code = kpu.run_yolo2(task, img)#运行 yolo2 网络
if code:
for i in code:
a = img.draw_rectangle(i.rect())
face_cut1 = img.cut(i.x()+20, i.y()-10, i.w()-40, 10)#剪切区域
a = img.draw_rectangle(i.x()+20, i.y()-10, i.w()-40, 10)
blobs = face_cut1.find_blobs([green_threshold])
if blobs:
a_2=1
panduan(a_2)
else:
a_2=2
panduan(a_2)
else:
img.draw_rectangle(0, 0, 320, 240, color = (255, 255, 0),thickness = 5, fill = False)
if a_3==1:
print("检测到")
img.draw_rectangle(0, 0, 320, 240, color = (0, 255, 0),thickness = 5, fill = False)
if a_3==2:
print("未检测到")
img.draw_rectangle(0, 0, 320, 240, color = (255, 0, 0),thickness = 5, fill = False)
a = lcd.display(img)
a = kpu.deinit(task)#反初始化
三、接线

四、最后效果
1.什么都检测不到屏幕亮黄灯
2.检测到人脸但是检测不到安全帽亮红灯,蜂鸣器响
3.检测到人脸检测到安全帽亮绿灯
五、改进计划
可以加上口罩检测把,之后颜色识别点多加上几个,没啥的了
边栏推荐
猜你喜欢

Oracle临时表详解

Unit test concept and purpose

Host FL Studio fruit music production daw20.9

Implementation of date class
![[untitled]](/img/96/7f26614bbdcce71006e38ee34ab216.jpg)
[untitled]

20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)

What if the disk of datanode is full?

New content violation degree determination scana bad information monitoring capability update issue 5

MySQL variables, stored procedures and functions

The principle of journal node
随机推荐
Ranger plug-in development (Part 2)
2022就要过去一半了,挣钱好难
C # generates PPK files in putty format (supports passphrase)
Hoo research | coinwave production - nym: building the next generation privacy infrastructure
Oracle-表的创建与管理
Double linked list: initialize insert delete traversal
Web compatibility testing of software testing
20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking
Error msb8031: building an MFC project for a non Unicode character set is deprecated
合适的工作就是好工作
Yboj mesh sequence [Lagrange interpolation]
Golang treasure house recommendation
Oracle-数据完整性
Ybtoj exchange game [tree chain splitting, line segment tree merging]
Usage of C set
Vnctf 2022 cm CM1 re reproduction
优质的水泵 SolidWorks模型素材推荐,不容错过
Deployment of mini version message queue based on redis6.0
Self examination before school starts
The communication mechanism and extension of Supervisor