深度学习:不到25行代码实现口罩识别(电脑端可直接运行)

深度学习:不到25行代码实现口罩识别(电脑端可直接运行)

  • 导入依赖
  • 代码实现
  • 参考

导入依赖


pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

代码实现

import cv2
import paddlehub as hub

module = hub.Module(name="pyramidbox_lite_mobile_mask")
video_capture = cv2.VideoCapture(0)
font = cv2.cv2.FONT_HERSHEY_SIMPLEX
while True:
    ret, frame = video_capture.read()

    results = module.face_detection(images=[frame], confs_threshold=0.5,shrink = 0.1)
    try:
        print(results)
        for i in results[0]['data']:
            if 'NO' not in i['label']:
                cv2.rectangle(frame, (i['left'], i['top']), (i['right'], i['bottom']), (0, 255, 0), 2)
                cv2.putText(frame, i['label']+str(round(i['confidence'],2)), (i['left'], i['top']), font, 1, (0, 255, 0), 1)
            else:
                cv2.rectangle(frame, (i['left'], i['top']), (i['right'], i['bottom']), (0, 0, 255), 2)
                cv2.putText(frame, i['label']+str(round(i['confidence'],2)), (i['left'], i['top']), font, 1, (0, 0, 255), 1)
    except:
        pass
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break
    cv2.imshow('Video', frame)

深度学习:不到25行代码实现口罩识别(电脑端可直接运行)_第1张图片

参考

opencv
paddlepaddle

你可能感兴趣的:(深度学习实践,机器学习,计算机视觉,opencv,目标检测,人工智能)