这年头,能有个开源的人脸库真是感天谢地了,而且可以在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 accuratedeep-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

![[深度学习] Python人脸识别库Deepface使用教程](https://img-blog.csdnimg.cn/img_convert/8b624f3fc366bb67c3633e23813e368b.png)
![[深度学习] Python人脸识别库face_recognition使用教程](https://img-blog.csdnimg.cn/img_convert/3ec970274e38e9daa167b45c8f8b3274.png)













