可以使用深度学习模型以达到更加精准的人脸定位,但要注意:这种方法需要GPU加速(通过英伟达显卡的CUDA库驱动),在编译安装dlib的时候也需要开启CUDA支持。
- import face_recognition
- image = face_recognition.load_image_file("my_picture.jpg")
- face_locations = face_recognition.face_locations(image, model="cnn")
- # face_locations is now an array listing the co-ordinates of each face
参考案例:
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py
如果有大量图片需要识别,同时又有GPU,那么你可以参考这个例子:
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py
如何识别单张图片中人脸的关键点?
- import face_recognition
- image = face_recognition.load_image_file("my_picture.jpg")
- face_landmarks_list = face_recognition.face_landmarks(image)
- # face_landmarks_list is now an array with the locations of each facial feature in each face.
- # face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye
参考案例:
https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py
识别奥巴马和拜登的人脸关键点
更多案例:
https://github.com/ageitgey/face_recognition/tree/master/examples
人脸定位
案例:定位拜登的脸
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py
案例:使用卷积神经网络深度学习模型定位拜登的脸
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py
案例:使用卷积神经网络深度学习模型批量识别图片中的人脸
https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py
案例:把来自网络摄像头视频里的人脸高斯模糊(需要安装OpenCV)
https://github.com/ageitgey/face_recognition/blob/master/examples/blur_faces_on_webcam.py
人脸关键点识别
案例:提取奥巴马和拜登的面部关键点
https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py
案例:给美国副总统拜登涂美妆
https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py
人脸识别
案例:是奥巴马还是拜登?
https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py
案例:人脸识别之后在原图上画框框并标注姓名
https://github.com/ageitgey/face_recognition/blob/master/examples/identify_and_draw_boxes_on_faces.py
案例:在不同精度上比较两个人脸是否属于一个人
https://github.com/ageitgey/face_recognition/blob/master/examples/face_distance.py
案例:从摄像头获取视频进行人脸识别-较慢版(需要安装OpenCV)
https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam.py
- 案例:从摄像头获取视频进行人脸识别-较快版(需要安装OpenCV)
https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py
- 案例:从视频文件中识别人脸并把识别结果输出为新的视频文件(需要安装OpenCV)
(编辑:ASP站长网)
|