paddlehub安装及对口罩检测

1、安装

python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install -i https://mirror.baidu.com/pypi/simple paddlehub

 报错,解决方案:

>pip install -i https://mirror.baidu.com/pypi/simple paddlehub --use-feature=2020-resolver

2、检测口罩

import paddlehub as hub
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import os
import cv2

# 加载口罩检测预训练模型
module = hub.Module(name="pyramidbox_lite_server_mask")
# 获取待检测图片
test_img_path = "mask.jpg"
imgs = [cv2.imread(test_img_path)]
# 口罩检测预测,结果保存
# visualization=True 将预测结果保存图片可视化
# output_dir='detection_result' 预测结果图片保存在当前运行路径下detection_result文件夹下
results = module.face_detection(images=imgs, use_multi_scale=True, shrink=0.6, visualization=True, output_dir='detection_result')
for result in results:
    print("result: %s" % result)
# 预测结果展示
path = os.path.join('detection_result', os.path.splitext(result['path'])[0] + '.jpg')
print('path: %s' %path)
img = mpimg.imread(path)
# 调用matplotlib, 相当于进入了另一个线程之中
plt.subplot(121)
plt.imshow(imgs[0])
plt.subplot(122)
plt.imshow(img)
plt.axis('off')
plt.show()

运行结果: 

参考自:Python 20行代码检测人脸是否佩戴口罩_51CTO博客_python人脸口罩识别检测

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chde2Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值