最简单有效的人脸检测方法
项目描述
YOLO 脸
You only look once (YOLO) is a state-of-the-art, real-time object detection system. It is based on Deep Learning.
Face detection is one of the important tasks of object detection. We apply a single neural network to the full image.
This project focuses on improving the accuracy of detecting the face using the model of deep learning network (YOLO).
This network divides the image into regions and predicts bounding boxes and probabilities for each region.
These bounding boxes are weighted by the predicted probabilities.
For this project, I am going to use YOLOv3, one of the most frequently used versions of the YOLO family, which comprises the
state-of-the-art object detection system for the real-time scenario and it is amazingly accurate and fast.
you can give the weights file created by training with YOLOv3 and our results on the custom dataset.
Also it has been added configuration files for use of weights file properly.
You want to test our face detection system you can use the following sample code sample.
用户安装:
如果您已经安装了 numpy 和 pandas,opencv 安装 yoloface 的最简单方法是使用 pip
pip install yoloface
这个包依赖于其他包:
# Prerequisites
1.numpy
2.cv2
3.os
4.PIL
5.gdown
6.time
7.IPython
用法
图像中的人脸检测
# import libraries
from yoloface import face_analysis
import numpy
import cv2
face=face_analysis() # Auto Download a large weight files from Google Drive.
# only first time.
# Automatically create folder .yoloface on cwd.
# example 1
%%time
img,box,conf=face.face_detection(image_path='path/to/jpg/or/png/filename.jpg',model='tiny')
print(box) # box[i]=[x,y,w,h]
print(conf) # value between(0 - 1) or probability
face.show_output(img,box)
# example 2
%%time
img,box,conf=face.face_detection(image_path='path/to/jpg/or/png/filename.jpg',model='full')
print(box)
print(conf)
face.show_output(img,box)
网络摄像头上的实时检测
from yoloface import face_analysis
import numpy
import cv2
# example 3
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
_,box,conf=face.face_detection(frame_arr=frame,frame_status=True,model='tiny')
output_frame=face.show_output(frame,box,frame_status=True)
cv2.imshow('frame',output_frame)
key=cv2.waitKey(1)
if key ==ord('v'):
break
cap.release()
cv2.destroyAllWindows()
#press v (exits)
# example 4
cap = cv2.VideoCapture(r'video file path.mp4')
while True:
_, frame = cap.read()
__,box,conf=face.face_detection(frame_arr=frame,frame_status=True,model='full')
output_frame=face.show_output(img=frame,face_box=box,frame_status=True)
print(box)
cv2.imshow('frame',output_frame)
key=cv2.waitKey(0)
if key ==ord('v'):
break
cap.release()
cv2.destroyAllWindows()
#press v (exits)
示例图像
输出图像 1
输出图像 2
输出图像 3
YOLOv3(You Only Look Once)是一种最先进的实时对象检测算法。已发布的模型可识别图像和视频中的 80 种不同对象。有关更多详细信息,您可以参考这篇论文。 参考链接
更改日志
0.0.3 (28/04/2021)
- 首次发布
0.0.4 (29/04/2021)
- 首次发布