#人脸比对 #导入百度ai和opencv from aip import AipFace import cv2 # 定义常量 APP_ID = '10736496' API_KEY = 'xLwFVx76ZmGujNxFGSGp8wUc' SECRET_KEY = 'H6jpVPX3wRdcxKf59r0qoGvG6zfHnMEk' # 初始化AipFace对象 client = AipFace(APP_ID, API_KEY, SECRET_KEY) """ 读取图片 """ def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() images = [ get_file_content('0.jpg'), get_file_content('1.jpg'), get_file_content('2.jpg'), ] """ 调用人脸比对 """ result=client.match(images) #输出比对结果 for k in range(3): print("图片%s和图片%s相似度:"%(result[ "result"][k]["index_i"],result[ "result"][k]["index_j"])) print(result[ "result"][k]["score"])