当前位置:网站首页>Face recognition_ recognition
Face recognition_ recognition
2022-07-06 11:24:00 【imxlw00】
Github Open source face recognition project face_recognition,face_recognition Is a powerful 、 Simple 、 Open source project of face recognition
install
pip install face_recognition
Import face_recognition modular
import face_recognition
load_image_file Load image
call face_recognition.load_image_file() Read image . The output image is rgb Format (opencv Medium is bgr Format )
import face_recognition
image = face_recognition.load_image_file("../datas/obama.jpg")
face_locations Face detection
It can locate the face position information recognized in all images , The return value is in list form , Each line in the list is the location information of a face , Include [top, right, bottom, left]
import face_recognition
import cv2
# Load the image file
image = face_recognition.load_image_file("../datas/hz.png")
image2 = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
cv2.imshow("src",image2)
face_locations = face_recognition.face_locations(image)
# Loop through all the faces found
for face_location in face_locations:
# Print the position information of each face
top, right, bottom, left = face_location
print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
# Specify the location information of the face , Then display the face picture
# face_image = image2[top:bottom, left:right]
# cv2.imshow("src2", face_image)
# Rectangle box
cv2.rectangle(image2, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.imshow("dest",image2)
cv2.waitKey(0)
face_landmarks() Key points of face recognition
call face_recognition.face_landmarks(image) The key point information of human face can be recognized , Including eyes 、 nose 、 Mouth and Chin
The return value is the list containing the facial feature dictionary , Each item in the list corresponds to a face , Include nose_bridge、right_eyebrow、right_eye、chine、left_eyebrow、bottom_lip、nose_tip、top_lip、left_eye Several parts , Each part contains several feature points (x,y), All in all 68 Characteristic points .
import cv2
import face_recognition
# Load the image file
image = face_recognition.load_image_file("images/ldh2.jpg")
image2 = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
face_landmarks_list = face_recognition.face_landmarks(image)
facial_features = [
'chin',
'left_eyebrow',
'right_eyebrow',
'nose_bridge',
'nose_tip',
'left_eye',
'right_eye',
'top_lip',
'bottom_lip'
]
thickness = 2
point_size = 1
point_color = (0, 255, 0) # BGR
for face_landmarks in face_landmarks_list:
for facial_feature in face_landmarks:
points_list = face_landmarks[facial_feature]
print("The {} in this face has the following points: {}".format(facial_feature, points_list))
# Draw each face feature in the image !
for point in points_list:
cv2.circle(image2, point, point_size, point_color, thickness)
cv2.imshow("dest",image2)
cv2.waitKey(0)
face_encodings() Face coding
Get the face code of each face in each image file , Every face is a 128 Dimension vector
import face_recognition
# Load the image file
image = face_recognition.load_image_file("images/ldh2.jpg")
face_encodings = face_recognition.face_encodings(image)
for face_encoding in face_encodings:
print("face_encoding len = {} \nencoding:{}\n\n".format(len(face_encoding),face_encoding))
face_encoding len = 128
encoding:[-0.12857245 0.2251953 -0.05680346 -0.009356 -0.07961649 -0.01976449
-0.03006363 -0.2188953 0.18227896 -0.06380306 0.23052536 -0.00517259
-0.24484953 -0.1024491 -0.07127093 0.10542907 -0.15712184 -0.24606238
-0.04181587 0.01180026 0.09390671 0.01014723 0.03316356 0.08216273
-0.08543567 -0.27527595 -0.10761252 -0.08561324 0.09562894 -0.06388975
-0.07860459 -0.01040951 -0.21186014 -0.10162984 0.09300554 0.08929634
-0.01133628 -0.02549033 0.25640246 -0.03459882 -0.22288607 0.06690408
0.05515105 0.31292963 0.14994277 0.06461242 0.00211182 -0.18974975
0.11956067 -0.07477805 0.09382927 0.21616243 0.18040094 0.02733615
0.03574533 -0.20213988 -0.00134893 0.08189995 -0.1417242 -0.00179647
0.10290838 -0.06461908 -0.01702856 -0.11400557 0.20824584 0.04568703
-0.07567319 -0.24240926 0.12750657 -0.16503944 -0.10546687 0.14743967
-0.13195604 -0.13922986 -0.26378733 -0.00479815 0.42761648 0.13261758
-0.17136547 0.09223576 -0.04313177 -0.03386433 0.07099032 0.1085121
-0.10494502 0.06504983 -0.15515642 -0.00395807 0.2313281 -0.01442198
-0.08458654 0.14688034 -0.00217457 0.07351732 0.06130501 0.01452726
-0.10001963 0.01601498 -0.12459313 -0.06574792 0.00460516 -0.01154638
-0.00899489 0.13434561 -0.14506203 0.06423949 -0.01264461 0.03912276
-0.06142928 0.01014899 -0.07765882 -0.04298633 0.10122736 -0.29780281
0.25160897 0.09939459 0.02078611 0.08443137 0.10742732 0.06015015
-0.00302691 -0.00466454 -0.20120506 -0.10478879 0.12094288 -0.0389271
0.19183818 -0.00275789]
compare_faces() Face matching
compare_faces() The method can match two facial feature codes , Using the inner product of two vectors to measure the similarity , Confirm whether it is the same face according to the threshold
The first parameter gives a list of face codes ( Many faces )
The second parameter gives a single face code ( A face )
Default parameters :tolerance=0.6, It can be changed according to your own needs ,tolerance The smaller the size, the tighter the match
The face that matches successfully returns True, Matching failed returns False, The order is consistent with the order of faces in the first parameter
matches ==face_recognition.compare_faces(known_face_encodings,face_encoding,tolerance=0.39)
import face_recognition
# Load pictures of known faces
known_image = face_recognition.load_image_file("images/yz1.jpg")
# Load pictures of unknown faces
unknown_image = face_recognition.load_image_file("images/yz2.jpg")
# load 2 A picture of a known face
ldh_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
# Calculate the distance between the unknown picture and the known picture
results = face_recognition.compare_faces([ldh_encoding], unknown_encoding,tolerance=0.39)[0]
print(results)
Reference link :https://blog.csdn.net/weixin_42213622/article/details/108193123
边栏推荐
- QT creator shape
- UDS learning notes on fault codes (0x19 and 0x14 services)
- [ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
- JDBC principle
- Project practice - background employee information management (add, delete, modify, check, login and exit)
- QT creator specify editor settings
- [recommended by bloggers] C # generate a good-looking QR code (with source code)
- Basic use of redis
- Ansible practical Series II_ Getting started with Playbook
- MySQL主从复制、读写分离
猜你喜欢
Copie maître - esclave MySQL, séparation lecture - écriture
QT creator test
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
MySQL与c语言连接(vs2019版)
Request object and response object analysis
02 staff information management after the actual project
[recommended by bloggers] background management system of SSM framework (with source code)
csdn-Markdown编辑器
Basic use of redis
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
随机推荐
【博主推荐】SSM框架的后台管理系统(附源码)
There are three iPhone se 2022 models in the Eurasian Economic Commission database
What does BSP mean
Django running error: error loading mysqldb module solution
One click extraction of tables in PDF
安全测试涉及的测试对象
Swagger, Yapi interface management service_ SE
Heating data in data lake?
AcWing 1298. Solution to Cao Chong's pig raising problem
How to configure flymcu (STM32 serial port download software) is shown in super detail
记某公司面试算法题:查找一个有序数组某个数字出现的次数
L2-006 树的遍历 (25 分)
Install mysql5.5 and mysql8.0 under windows at the same time
L2-007 家庭房产 (25 分)
Rhcsa certification exam exercise (configured on the first host)
[recommended by bloggers] C # generate a good-looking QR code (with source code)
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
Asp access Shaoxing tourism graduation design website
[蓝桥杯2020初赛] 平面切分