当前位置:网站首页>K210 site helmet
K210 site helmet
2022-07-01 01:16:00 【Mrli0530】
Human body wearing safety helmet detection :
1. Nothing can be detected. The screen lights up yellow
2. The face is detected, but the helmet is not detected. The red light is on , Buzzer ring
3. Face detected, helmet detected, green light on
One 、 Ideas
1. Formal thinking : First use YOLO Face detection (320240) Then cut out the image (224224) Into another YOLO Carry out helmet inspection , That's the idea .
2. shortcut : First use YOLO Face detection (320*240) Get a little bit of the upper edge of the face (ROI), Then use color recognition to ROI Area for color recognition , After recognizing the corresponding color, it is recognized
, Finally, the actual use is 2
Two 、 Program
1. The final procedure
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)
#********************* Judge ********************#
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(" Performing filtering algorithm , The first ",a_1,"/ common 25 Time ")
else:
a_3=max(e_1, default=' The list is empty. ', 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)
#******************* Variable *************************#
b_1=b_2=0
a_2=a_4=0
c_1=c_2=0
d_1=d_2=d_3=0
sss=0# Record the number of tests
global a_3
#******************* Pin **************************#
fpioa = FPIOA()
fpioa.set_function(0,fpioa.GPIOHS0)# Buzzer
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(" detected ")
led2.value(0)
img.draw_rectangle(0, 0, 320, 240, color = (0, 255, 0),thickness = 5, fill = False)
if a_3==2:
print(" Not detected ")
led2.value(1)
img.draw_rectangle(0, 0, 320, 240, color = (255, 0, 0),thickness = 5, fill = False)
if a_3==3:
print(" Not detected ")
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. The final procedure
In fact, this method can , Data collection is not in place .
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)
#************************ neural network ******************************#
task = kpu.load(0x300000) # You need to put the model (face.kfpkg) In the flash address 0x300000
# Model tracing parameters
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
# initialization yolo2 The Internet
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
green_threshold = (50, 82, -22, 18, 11, 70)
#******************* Pin **************************#
fpioa = FPIOA()
fpioa.set_function(11,fpioa.GPIOHS0)
led1 = GPIO(GPIO.GPIOHS0,GPIO.OUT)
led1.value(0)
fpioa.set_function(10,fpioa.GPIOHS1)# Buzzer
led2 = GPIO(GPIO.GPIOHS1,GPIO.OUT)
led2.value(0)
fpioa.set_function(9,fpioa.GPIOHS2)# The lamp
led3 = GPIO(GPIO.GPIOHS2,GPIO.OUT)
led3.value(0)
#******************* Variable *************************#
b_1=b_2=0
a_1=a_2=a_3=a_4=0
c_1=c_2=0
sss=0# Record the number of tests
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]
#********************* Judge ********************#
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(" Performing filtering algorithm , The first ",a_1,"/ common 25 Time ")
else:
a_3=max(e_1, default=' The list is empty. ', 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)# function yolo2 The Internet
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)# The shear zone
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(" detected ")
img.draw_rectangle(0, 0, 320, 240, color = (0, 255, 0),thickness = 5, fill = False)
if a_3==2:
print(" Not detected ")
img.draw_rectangle(0, 0, 320, 240, color = (255, 0, 0),thickness = 5, fill = False)
a = lcd.display(img)
a = kpu.deinit(task)# Uninitialize
3、 ... and 、 connection

Four 、 The final result
1. Nothing can be detected. The screen lights up yellow
2. The face is detected, but the helmet is not detected. The red light is on , Buzzer ring
3. Face detected, helmet detected, green light on
5、 ... and 、 Improvement plan
You can add a mask to detect , Then add a few more color recognition points , It's nothing
边栏推荐
- The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
- Set different background colors for the border and text of the button
- XJY-220/43AC220V静态信号继电器
- [learning notes] structure
- Q弹松软的大号吐司,带来更舒服的睡眠
- Oracle table creation and management
- Practical shell knowledge
- The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
- 06.论Redis持久化的几种方式
- Experiment 8 T-SQL, stored procedure
猜你喜欢

Koa koa-combine-routers 分路由管理

Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support

Exploring the road of steam education innovation in the Internet Era

Can JDBC based on openjdk connect to MySQL?

给按钮的边框和文字设置不同的背景色

Vnctf 2022 cm CM1 re reproduction

C # Generate PPK files in Putty format (passthrough support)

K210工地安全帽

P4 learning - Basic tunneling

Shift operators
随机推荐
C # Generate PPK files in Putty format (passthrough support)
Golang treasure house recommendation
Join table query select generation
Inspire students' diversified thinking with steam Education
Q弹松软的大号吐司,带来更舒服的睡眠
[learning notes] double + two points
Practical shell knowledge
None of the following candidates is applicable because of a receiver type mismatch
ArrayList analysis 1-cycle, capacity expansion, version
K210工地安全帽
Share your own terminal DIY display banner
剑指 Offer 18. 删除链表的节点
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
[go] go implements row column conversion of sets
(学习力+思考力) x 行动力,技术人成长的飞轮效应总结
Authentication principle of Ranger plug-in
孔乙己第一问之服务通信知多少?
js中把数字转换成汉字输出
TCP三次握手为什么不是两次或四次
分割链表[先取next再斩断链表防止断链]