Opencv比较两个人脸嵌入

Open cv compare two face embeddings

我经历了Pyimagesearch face Recognition tutorial, 但我的应用程序只需要比较两张脸, 我嵌入了两张脸,如何使用 opencv 比较它们? link中提到了关于用于从面部提取嵌入的训练模型, 我想知道我应该尝试用什么方法来比较两个人脸嵌入。

(注:我是新手)

首先,您的案例与给定的教程相似,您需要将单张图像与测试图像进​​行比较,而不是多张图像,

所以你真的不需要训练步骤。

你可以做到

# read 1st image and store encodings
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

boxes = face_recognition.face_locations(rgb, model=args["detection_method"])
encodings1 = face_recognition.face_encodings(rgb, boxes)

# read 2nd image and store encodings
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

boxes = face_recognition.face_locations(rgb, model=args["detection_method"])
encodings2 = face_recognition.face_encodings(rgb, boxes)


# now you can compare two encodings
# optionally you can pass threshold, by default it is 0.6
matches = face_recognition.compare_faces(encoding1, encoding2)

matches 会根据你的图片给你 TrueFalse

根据您提到的文章,您实际上可以仅使用 face_recognition library.

来比较两张脸是否相同

可以使用compare faces判断两张图片是否是同一张脸

import face_recognition
known_image = face_recognition.load_image_file("biden.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")

biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]

results = face_recognition.compare_faces([biden_encoding], unknown_encoding)