python 百度AI 人脸对比 实现示例

百度AI: from aip import AipFace

百度aip下载:

cmd: pip3 install aip                                           (适用于python3,python2 去掉3就ok了)

人脸对比传入参数:

client.match([{参数1},{参数2}])

功能:给出相似度,并返回实现设置好对比度的答案。

具体代码实现如下:(复制粘贴就可以玩哦)

from aip import AipFace
import base64

APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client = AipFace(APP_ID, API_KEY, SECRET_KEY)

IMAGE_TYPE = 'BASE64'

f1 = open ( '1.jpg' , 'rb' )
f2 = open ( '2.jpg' , 'rb' )
#参数image:图像base64编码 分别base64编码后的2张图片数据
img1 = base64.b64encode(f1.read())
img2 = base64.b64encode(f2.read())
image_1 = str (img1, 'utf-8' )
image_2 = str (img2, 'utf-8' )

ptr = client.match([
    {
        'image' : image_1,
        'image_type' : 'BASE64' ,
    },
    {
        'image' : image_2,
        'image_type' : 'BASE64' ,
    }
])
ptr = ptr[ 'result' ]
if ptr[ 'score' ] <= 50 :
    print ( '这俩人不像:哈哈哈' ,ptr[ 'score' ])
else :
    print ( 'piupiupiu:孪生兄弟啊' ,ptr[ 'score' ])

猜你喜欢

转载自blog.csdn.net/nightchenright/article/details/80875079