当前位置:网站首页>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.检测到人脸检测到安全帽亮绿灯
五、改进计划
可以加上口罩检测把,之后颜色识别点多加上几个,没啥的了
边栏推荐
- None of the following candidates is applicable because of a receiver type mismatch
- Multi graph explanation of resource preemption in yarn capacity scheduling
- Solving the weird problem that the query conditions affect the value of query fields in MySQL query
- Error msb8031: building an MFC project for a non Unicode character set is deprecated
- Listview in flutter application development
- 最长的可整合子数组的长度
- The communication mechanism and extension of Supervisor
- Implementation of date class
- Redis based distributed lock
- C # Generate PPK files in Putty format (passthrough support)
猜你喜欢
Get to know the drawing component of flutter - custompaint
P4学习——Basic Tunneling
20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
MySQL variables, stored procedures and functions
Practical shell knowledge
C # generates PPK files in putty format (supports passphrase)
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
Wechat official account development (1) introduction to wechat official account
NE555波形发生器手把手教程之NE555内部结构(一)
CTF tool (1) -- archpr -- including installation / use process
随机推荐
The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
leetcode 474. Ones and zeroes (medium)
JS bubble sort and select sort
Sword finger offer 19 Regular Expression Matching
Experiment 8 T-SQL, stored procedure
优质的水泵 SolidWorks模型素材推荐,不容错过
New content violation degree determination scana bad information monitoring capability update issue 5
Multi graph explanation of resource preemption in yarn capacity scheduling
Host FL Studio fruit music production daw20.9
P4学习——p4runtime
Basic data structure of redis
Vulnerability discovery - App application vulnerability probe type utilization and repair
Sword finger offer 18 Delete the node of the linked list
Date类的实现
How to do the performance pressure test of "Health Code"
问题解决:如何管理线程私有(thread_local)的指针变量
Cmu15445 (fall 2019) project 1 - buffer pool details
Redis based distributed lock
Fluent JSON serialization deserialization
什么是产品思维