posted on 2023-05-21 16:40 read(628) comment(0) like(13) collect(5)
Face recognition is different from face detection. In face detection, we only detected the location of the face, and in face recognition task, we identified the identity of the person.
This article focuses on implementing face recognition using the library face_recognition, which is based on deep learning techniques and promises over 96% accuracy using a single training image.
Identify system use cases
Traditional face recognition algorithms do not meet modern face recognition standards. They are designed to recognize faces using old legacy algorithms.
OpenCV provides some traditional facial recognition algorithms.
These methods differ in the way they extract image information and match input and output images.
The LBPH algorithm is a simple but very effective method that is still in use, but is slower compared to modern algorithms.
There are various deep learning based facial recognition algorithms available.
Generally speaking, a landmark-based face recognizer takes an image of a face and tries to find basic feature points such as eyebrows, mouth corners, eyes, nose, lips, etc. There are more than 60 landmarks.
Use python to implement a face recognition system. Use the face_recognition library to implement a face recognition system based on deep learning.
In order to install the face recognition library, we need to install dlib first
pip install dlib
pip install face recognition
pip install opencv
Note: Sometimes installing dlib throws error in that case install install the C++ development toolkit using vs_code community .
导入库
import cv2
import numpy as np
import face_recognition
我们完成了库的安装和导入。是时候将一些示例图像加载到face_recognition库中了。
该face_recognition库仅支持 BGR 格式的图像。在打印输出图像时,我们应该使用 OpenCV 将其转换为 RGB。
Face_recognition仅加载 BGR 格式的图像。
import cv2
import numpy as np
import face_recognition
img_bgr = face_recognition.load_image_file('student_images/modi.jpg')
img_rgb = cv2.cvtColor(img_bgr,cv2.COLOR_BGR2RGB)
cv2.imshow('bgr', img_bgr)
cv2.imshow('rgb', img_rgb)
cv2.waitKey
输出→ BGR 与 RGB
face_recognition库可以自行快速定位人脸,我们不需要使用haar_cascade或其他技术。
img_modi=face_recognition.load_image_file('student_images/modi.jpg')
img_modi_rgb = cv2.cvtColor(img_modi,cv2.COLOR_BGR2RGB)
#--------- Detecting Face -------
face = face_recognition.face_locations(img_modi_rgb)[0]
copy = img_modi_rgb.copy()
# ------ Drawing bounding boxes around Faces------------------------
cv2.rectangle(copy, (face[3], face[0]),(face[1], face[2]), (255,0,255), 2)
cv2.imshow('copy', copy)
cv2.imshow('MODI',img_modi_rgb)
cv2.waitKey(0)
该face_recognition库基于深度学习,它支持单次学习,这意味着它需要一张图片来训练自己检测一个人。
img_modi = face_recognition.load_image_file('student_images/modi.jpg')
img_modi = cv2.cvtColor(img_modi,cv2.COLOR_BGR2RGB)
#------to find the face location
face = face_recognition.face_locations(img_modi)[0]
#--Converting image into encodings
train_encode = face_recognition.face_encodings(img_modi)[0]
#----- lets test an image
test = face_recognition.load_image_file('student_images/modi2.jpg')
test = cv2.cvtColor(test, cv2.COLOR_BGR2RGB)
test_encode = face_recognition.face_encodings(test)[0]
print(face_recognition.compare_faces([train_encode],test_encode))
cv2.rectangle(img_modi, (face[3], face[0]),(face[1], face[2]), (255,0,255), 1)
cv2.imshow('img_modi', img_modi)
cv2.waitKey(0)
上面的代码拍了两张总理的照片,因为两张照片都是同一个人,所以它返回了true。
Author:kimi
link:http://www.pythonblackhole.com/blog/article/25267/85edf7c957a96eb5746f/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!