AI人脸匹对
人脸匹对
技术
调用到百度的AI接口,layui的图片上传,栅格化布局
核心代码
纯py代码运行
# encoding:utf-8 from aip import AipFace import base64 """ 你的APPID,API_KEY和SECRET_KEY """ APP_ID = '' API_KEY = '' SECRET_KEY = '' # 封装成函数,返回获取的client对象 def get_client(APP_ID, API_KEY, SECRET_KEY): """ 返回client对象 :param APP_ID: :param API_KEY: :param SECRET_KEY: :return: """ return AipFace(APP_ID, API_KEY, SECRET_KEY) client = get_client(APP_ID, API_KEY, SECRET_KEY) result = client.match([ { 'image': str(base64.b64encode(open('img/me.jpg', 'rb').read()), 'utf-8'), 'image_type': 'BASE64', }, { 'image': str(base64.b64encode(open('img/xlf.jpg', 'rb').read()), 'utf-8'), 'image_type': 'BASE64', } ]) if result['error_msg'] == 'SUCCESS': score = result['result']['score'] if score>80: print("照片相似度为:"+str(score)+"基本确定是本人") else: print("照片相似度为:" + str(score) + "基本确定不是本人") print(score) else: print('错误信息:', result['error_msg'])
实战开发-人脸匹对
操作
1.准备页面:两个图片上传,一个为原图,一个为比对图
2.上传照片后,当点击“智能对比”就会将两张图片的地址发送到后端,通过上面的纯py代码,将结果返还给前端
3.前端将结果进行展示即可
展示