我正在使用face_recognition包进行人脸识别
输入图像文件是base64编码的
我试图解码数据,然后
face_recognition.face_encodings(decodedBase64Data)
我有面部编码的数据列表要比较
问题是我需要将base64数据转换为可以使用face_编码的图像
我试过了
decodedData = base64.b64decode(data)
encodeFace = np.frombuffer(decodedData, np.uint8)
并将已编码的面传递给
face_recognition.face_encodings(decodedBase64Data)
我得到错误Unsupported image type, must be 8bit gray or RGB image.
如何将base64转换为与face_编码兼容的图像
编辑:
附代码以供参考
import base64
import numpy as np
import json
import face_recognition as fr
with open('Face_Encoding_Data.json') as f:
EncodeJsonData = json.load(f)
personName = list(EncodeJsonData.keys())
encodedImgList = list(EncodeJsonData.values())
"""
EncodeJsonData = {"name1" : [encoded data 1], "name2" : [encoded data 2]}
128 byte
"""
base64Data = """ base64 encoded image with face """
encodeFace = np.frombuffer(base64.b64decode(base64Data), np.uint8)
matches = fr.compare_faces(encodedImgList, encodeFace, tolerance=0.5)
faceDist = fr.face_distance(encodedImgList, encodeFace)
matchIndex = np.argmin(faceDist)
name = "unknown"
if matches[matchIndex]:
name = personName[matchIndex]
print(name)
请共享代码以更好地理解问题,或者您可以使用以下代码作为参考
相关问题 更多 >
编程相关推荐