基于百度AI的人脸识别

https://cloud.baidu.com/doc/FACE/Face-Match.html#.E4.BA.BA.E8.84.B8.E5.AF.B9.E6.AF.94-1
连接是百度ai的技术文档,里面有具体说明。

1.读取url图片进行识别

   from aip import AipFace
    
    """ 你的 APPID AK SK """
    APP_ID = ''
    API_KEY = ''
    SECRET_KEY = ''
    
    client = AipFace(APP_ID, API_KEY, SECRET_KEY)
    
    #你的图片
    image = xxxx.jpg"
    
    imageType = "URL"
    
    """ 如果有可选参数 """
    options = {}
    options["face_field"] = "age,beauty"
    options["max_face_num"] = 1
    options["face_type"] = "LIVE"
    
    """ 带参数调用人脸检测 """
    client.detect(image, imageType, options)
    
    result = client.detect(image, imageType, options)
    print(result)

2.转base64识别

from aip import AipFace
import base64
import sys
""" 你的 APPID AK SK """
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''

client = AipFace(APP_ID, API_KEY, SECRET_KEY)


filePath = str(sys.argv[1])
print('正在载入:')
print(filePath)
with open(filePath,"rb") as f:
# b64encode是编码
    base64_data = base64.b64encode(f.read())
image = str(base64_data,'utf-8')
imageType = "BASE64"

#参数设置
options = {}
options["face_field"] = "age,beauty"
options["max_face_num"] = 1
options["face_type"] = "LIVE"

""" 调用人脸检测 """
result = client.detect(image, imageType,options);
print(result)
print(result["result"]["face_num"])

3.人脸库对比

from aip import AipFace
import base64
import sys
""" 你的 APPID AK SK """
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''

client = AipFace(APP_ID, API_KEY, SECRET_KEY)


filePath = str(sys.argv[1])
print('正在载入:')
print(filePath)
with open(filePath,"rb") as f:
# b64encode是编码
	base64_data = base64.b64encode(f.read())
image = str(base64_data,'utf-8')
imageType = "BASE64"

#需要在百度ai里面设置
groupIdList = ""

""" 调用人脸搜索 """
a = client.search(image, imageType, groupIdList);

print(a)
#选择需要的参数
print(a["result"]["user_list"])

你可能感兴趣的:(python识别)