深度学习系列18:开源人脸识别库

Posted IE06

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了深度学习系列18:开源人脸识别库相关的知识,希望对你有一定的参考价值。

这年头,能有个开源的人脸库真是感天谢地了,而且可以在arm机器上使用,真不容易。git地址见https://github.com/ageitgey/face_recognition

1. 人脸检测

人脸检测可以选hog和cnn两种。默认用hog(在cpu上用cnn真的很慢)。这个人脸检测对于口罩的识别率不高,慎用。
在使用gpu时,还可以使用批量人脸检测:
face_recognition.batch_face_locations(frames, number_of_times_to_upsample=0)

import cv2
image = face_recognition.load_image_file("....png")
face_locations = face_recognition.face_locations(image,model='cnn')
for r in face_locations:
    cv2.rectangle(image,(r[1],r[0]),(r[3],r[2]),(255,0,0),5) # 注意这里的顺序!
io.imshow(image)

说明如下:

Signature:
face_recognition.face_locations(
    img,
    number_of_times_to_upsample=1,
    model='hog',
)
Docstring:
Returns an array of bounding boxes of human faces in a image

:param img: An image (as a numpy array)
:param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
:param model: Which face detection model to use. "hog" is less accurate but faster on CPUs. "cnn" is a more accurate
              deep-learning model which is GPU/CUDA accelerated (if available). The default is "hog".
:return: A list of tuples of found face locations in css (top, right, bottom, left) order

2. 人脸关键点检测

face_landmarks_list = face_recognition.face_landmarks(image)

结果如下:
在这里插入图片描述

3. 人脸识别

res = face_recognition.face_encodings(image)

说明如下:

Signature:
face_recognition.face_encodings(
    face_image,
    known_face_locations=None,
    num_jitters=1,
    model='small',
)
Docstring:
Given an image, return the 128-dimension face encoding for each face in the image.

:param face_image: The image that contains one or more faces
:param known_face_locations: Optional - the bounding boxes of each face if you already know them.
:param num_jitters: How many times to re-sample the face when calculating encoding. Higher is more accurate, but slower (i.e. 100 is 100x slower)
:param model: Optional - which model to use. "large" (default) or "small" which only returns 5 points but is faster.
:return: A list of 128-dimensional face encodings (one for each face in the image)
File:      ~/anaconda3/lib/python3.7/site-packages/face_recognition/api.py
Type:      function

以上是关于深度学习系列18:开源人脸识别库的主要内容,如果未能解决你的问题,请参考以下文章

[深度学习工具]·极简安装Dlib人脸识别库

用 20 行 python 代码实现人脸识别!

深度学习| 基于keras以及cv2实现人脸识别

识别人脸face_recognition实现

[深度学习][转载]人脸识别相似度计算方法

64行代码实现简单人脸识别