在小藤上实现安全帽识别

举报
张辉 发表于 2023/09/01 07:50:29 2023/09/01
【摘要】 在小藤上实现安全帽识别
登录开发板:
cd ~/ascend_community_projects/HelmetIdentification_V2
获取onnx模型:
cd model
wget https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/HelmetIdentification/model.zip --no-check-certificate
解压 unzip model.zip 并将onnx文件移到当前目录下:
开始模型转换,文档指南中脚本有点问题,文档中叫做atc-env.sh,实际上是act-env.sh:
张小白觉得这种脚本写得麻烦,还得改,不如换种方法运行:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /home/HwHiAiUser/mxVision-5.0.RC2/set_env.sh
atc --model=./YOLOv5_s.onnx --framework=5 --output=YOLOv5_s --insert_op_conf=./aipp_YOLOv5.config --input_format=NCHW --log=info --soc_version=Ascend310B1 --input_shape="images:1,3,640,640"

查看toolkit目录:/usr/local/Ascend/ascend-toolkit/latest
cd ../src
修改CMakeList.txt,将24行和35行改为 /usr/local/Ascend/ascend-toolkit/latest 目录下的include和lib64目录:
由于代码提供了对video和image的不同main.cpp
为了便于测试,选用image的。将两个文件备份后,留下main-image.cpp
rm main.cpp
mv main-image.cpp main.cpp
编译代码:
cd ..
mkdir build
cd build
cmake ..
make
报opencv2的目录不对。
嗯。是因为张小白换了个终端执行的编译,环境变量没更新进去,设置环境变量:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /home/HwHiAiUser/mxVision-5.0.RC2/set_env.sh
重新编译:
cd ~/ascend_community_projects/HelmetIdentification_V2
mkdir build
cd build
cmake ..
make
-lavformat 这几个av库没找到,但是显然这几个库在/usr/lib/aarch64-linux-gnu 下都有:
在src/CMakeLists.txt文件中的link_directories下增加这个配置:
重新编译:
cd ~/ascend_community_projects/HelmetIdentification_V2
rm -rf build
mkdir build
cd build
cmake ..
make
怎么没生效?
切换到root,做三个软链接试试:
cd /usr/lib/aarch64-linux-gnu
ln -s libavformat.so.58 libavformat.so
ln -s libavcodec.so.58 libavcodec.so
ln -s libavutil.so.56 libavutil.so
再来一次:
编译好的可执行文件 main放在了基目录下:
找2张图片,一张带安全帽的,一张不带安全帽的。
1.jpg
2.jpg
mkdir -p ~/ascend_community_projects/HelmetIdentification_V2/dataSet/TestImages
将文件传到 ~/ascend_community_projects/HelmetIdentification_V2/dataSet/TestImages目录下
cd ~/ascend_community_projects/HelmetIdentification_V2/
./main 1
结果用文本表示如下:
(base) HwHiAiUser@davinci-mini:~/ascend_community_projects/HelmetIdentification_V2$ ./main 1
Begin to initialize Log.
The output directory of logs file exist.
WARNING: Logging before InitGoogleLogging() is written to STDERR
I20230826 17:15:23.350164 565598 FileUtils.cpp:330] The input file is empty
I20230826 17:15:23.350229 565598 FileUtils.cpp:472] Check Other group permission: Current permission is 4, but required no greater than 0.
Save logs information to specified directory.
E20230826 17:15:24.392661 565598 main.cpp:70] Decode failed, ret=0
===---> Size of objectInfos is 1
objectInfo-0 , Size:17

*****objectInfo-0:0
x0 is 1197.88
y0 is 414.076
x1 is 1316.34
y1 is 639.116
confidence is 0.9207
classId is 0
className is person

*****objectInfo-0:1
x0 is 160.054
y0 is 370.813
x1 is 326.935
y1 is 682.745
confidence is 0.909781
classId is 0
className is person

*****objectInfo-0:2
x0 is 941.889
y0 is 352.407
x1 is 1105.92
y1 is 589.61
confidence is 0.908163
classId is 0
className is person

*****objectInfo-0:3
x0 is 663.807
y0 is 207.473
x1 is 854.542
y1 is 568.895
confidence is 0.891245
classId is 0
className is person

*****objectInfo-0:4
x0 is 693.815
y0 is 453.143
x1 is 889.863
y1 is 721.335
confidence is 0.880824
classId is 0
className is person

*****objectInfo-0:5
x0 is 1118.52
y0 is 522.384
x1 is 1282.55
y1 is 812.88
confidence is 0.86435
classId is 0
className is person

*****objectInfo-0:6
x0 is 360.87
y0 is 441.587
x1 is 525.374
y1 is 815.926
confidence is 0.857629
classId is 0
className is person

*****objectInfo-0:7
x0 is 464.084
y0 is 333.515
x1 is 621.346
y1 is 646.729
confidence is 0.812785
classId is 0
className is person

*****objectInfo-0:8
x0 is 1112.39
y0 is 518.19
x1 is 1185.57
y1 is 601.578
confidence is 0.802804
classId is 1
className is head

*****objectInfo-0:9
x0 is 1231.63
y0 is 409.1
x1 is 1290.05
y1 is 474.891
confidence is 0.801329
classId is 1
className is head

*****objectInfo-0:10
x0 is 489.709
y0 is 333.067
x1 is 547.104
y1 is 397.829
confidence is 0.787573
classId is 1
className is head

*****objectInfo-0:11
x0 is 985.085
y0 is 351.291
x1 is 1042.24
y1 is 417.952
confidence is 0.77055
classId is 1
className is head

*****objectInfo-0:12
x0 is 414.379
y0 is 449.321
x1 is 481.998
y1 is 523.189
confidence is 0.704588
classId is 1
className is head

*****objectInfo-0:13
x0 is 221.515
y0 is 369.891
x1 is 285.274
y1 is 445.894
confidence is 0.58699
classId is 1
className is head

*****objectInfo-0:14
x0 is 737.581
y0 is 454.191
x1 is 804.873
y1 is 541.098
confidence is 0.853783
classId is 2
className is helmet

*****objectInfo-0:15
x0 is 737.151
y0 is 204.939
x1 is 804.103
y1 is 281.154
confidence is 0.815781
classId is 2
className is helmet

*****objectInfo-0:16
x0 is 221.498
y0 is 369.766
x1 is 286.354
y1 is 444.487
confidence is 0.555514
classId is 2
className is helmet
(base) HwHiAiUser@davinci-mini:~/ascend_community_projects/HelmetIdentification_V2$
./main 2
结果用文本表示如下:
(base) HwHiAiUser@davinci-mini:~/ascend_community_projects/HelmetIdentification_V2$ ./main 2
Begin to initialize Log.
The output directory of logs file exist.
WARNING: Logging before InitGoogleLogging() is written to STDERR
I20230826 17:16:59.419138 566577 FileUtils.cpp:330] The input file is empty
I20230826 17:16:59.419196 566577 FileUtils.cpp:472] Check Other group permission: Current permission is 4, but required no greater than 0.
Save logs information to specified directory.
E20230826 17:17:00.495553 566577 main.cpp:70] Decode failed, ret=0
===---> Size of objectInfos is 1
objectInfo-0 , Size:4

*****objectInfo-0:0
x0 is 195.508
y0 is 162.186
x1 is 625.113
y1 is 604.213
confidence is 0.741041
classId is 0
className is person

*****objectInfo-0:1
x0 is 497.02
y0 is 165.186
x1 is 603.942
y1 is 297.213
confidence is 0.865298
classId is 1
className is head

*****objectInfo-0:2
x0 is 727.538
y0 is 168.107
x1 is 829.941
y1 is 307.153
confidence is 0.838571
classId is 1
className is head

*****objectInfo-0:3
x0 is 978.615
y0 is 200.588
x1 is 1077.86
y1 is 322.825
confidence is 0.836248
classId is 1
className is head
(base) HwHiAiUser@davinci-mini:~/ascend_community_projects/HelmetIdentification_V2$
从这个代码可以看出,其实并不存在什么专门的安全帽识别,只是有没有物体被识别成安全帽这个类别。
第一张图,className is helmet 表示识别出了安全帽。
第二张图,显然没有安全帽。
张小白想了想,这种判断逻辑还是存在问题的。它使用yolov5来识别有没有安全帽,但是安全帽是否戴在人的头上它不知道。万一这个人手上拿着个安全帽,这种识别的结果就可能是错误的。可能需要判断安全帽的位置和人脸的位置的接近程度(比如说必须是相邻且在上方)才能判断是佩戴了安全帽。
所以这个例子恐怕也只能玩一玩。
(全文完,谢谢阅读)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。