【Demo】使用Dlib从相机进行人脸识别
文件列表(压缩包大小 106.68M)
免费
概述
使用Dlib从相机进行人脸识别
调用摄像头进行人脸识别,支持多张人脸同时识别;
请不要离摄像头过近,人脸超出摄像头范围时会有 "OUT OF RANGE" 提醒;
提取特征建立人脸数据库
利用摄像头进行人脸识别
单张人脸
利用 OT 对于单张人脸追踪
多张人脸
利用 OT 来实现
定制显示名字, 可以写中文
关于精度:
关于算法:
此项目中人脸识别的实现流程 (no OT, 每一帧都进行检测+识别)
实现流程(with OT, 初始帧进行检测+识别,后续帧检测+质心跟踪)
如果利用 OT 来跟踪,可以大大提高 FPS, 因为做识别时候需要提取特征描述子的耗时很多;
安装依赖库
pip3 install opencv-python
pip3 install scikit-image
pip3 install dlib
下载源码
git clone https://github.com/coneypo/Dlib_face_recognition_from_camera
进行人脸信息采集录入
python3 get_face_from_camera.py
提取所有录入人脸数据存入 "features_all.csv"
python3 features_extraction_to_csv.py
调用摄像头进行实时人脸识别
python3 face_reco_from_camera.py
或者利用 OT 算法,调用摄像头进行实时人脸识别
python3 face_reco_from_camera_ot_single_person.py
python3 face_reco_from_camera_ot_multi_people.py
.
├── get_faces_from_camera.py # Step 1. Face register
├── features_extraction_to_csv.py # Step 2. Feature extraction
├── face_reco_from_camera.py # Step 3. Face recognizer
├── face_reco_from_camera_ot_single_person.py # Step 3. Face recognizer with OT for single person
├── face_reco_from_camera_ot_multi_people.py # Step 3. Face recognizer with OT for multi people
├── face_descriptor_from_camera.py # Face descriptor computation
├── how_to_use_camera.py # Use the default camera by opencv
├── data
│ ├── data_dlib # Dlib's model
│ │ ├── dlib_face_recognition_resnet_model_v1.dat
│ │ └── shape_predictor_68_face_landmarks.dat
│ ├── data_faces_from_camera # Face images captured from camera (will generate after step 1)
│ │ ├── person_1
│ │ │ ├── img_face_1.jpg
│ │ │ └── img_face_2.jpg
│ │ └── person_2
│ │ └── img_face_1.jpg
│ │ └── img_face_2.jpg
│ └── features_all.csv # CSV to save all the features of known faces (will generate after step 2)
├── README.rst
└── requirements.txt # Some python packages needed
detector = dlib.get_frontal_face_detector()
faces = detector(img_gray, 0)
# This is trained on the ibug 300-W dataset (https://ibug.doc.ic.ac.uk/resources/facial-point-annotations/)
# Also note that this model file is designed for use with dlib's HOG face detector.
# That is, it expects the bounding boxes from the face detector to be aligned a certain way, the way dlib's HOG face detector does it.
# It won't work as well when used with a face detector that produces differently aligned boxes,
# such as the CNN based mmod_human_face_detector.dat face detector.
predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_68_face_landmarks.dat")
shape = predictor(img_rd, faces[i])
face_rec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")
get_face_from_camera.py: 进行 Face register / 人脸信息采集录入
features_extraction_to_csv.py: 从上一步存下来的图像文件中,提取人脸数据存入CSV;
face_reco_from_camera.py: 这一步将调用摄像头进行实时人脸识别; / This part will implement real-time face recognition;
face_reco_from_camera_ot_single_person/multi_people.py: 区别于 face_reco_from_camera.py (对每一帧都进行检测+识别),只会对初始帧做检测+识别,对后续帧做检测+质心跟踪;
(optional) face_descriptor_from_camera.py 调用摄像头进行实时特征描述子计算; / Real-time face descriptor computation;
如果希望详细了解 dlib 的用法,请参考 Dlib 官方 Python api 的网站 / You can refer to this link for more information of how to use dlib: http://dlib.net/python/index.html
Windows下建议不要把代码放到 C:\
, 可能会出现权限读取问题 / In windows, we will not recommend that running this repo in dir C:\
代码最好不要有中文路径
人脸录入的时候先建文件夹再保存图片, 先 N
再 S
关于人脸识别卡顿 FPS 低问题, 原因是特征描述子提取很费时间, 光跑 face_descriptor_from_camera.py 中 face_reco_model.compute_face_descriptor 在 CPU: i7-8700K 得到的最终 FPS: 5~6 (检测在 0.03s, 特征描述子提取在 0.158s, 和已知人脸进行遍历对比在 0.003s 左右), 所以主要提取特征时候耗资源, 可以用 OT 去做追踪,而不是对每一帧都做检测+识别
来源https://github.com/coneypo/Dlib_face_recognition_from_camera
如果遇到文件不能下载或其他产品问题,请添加管理员微信:ligongku001,并备注:产品反馈