天天看點

【人臉檢測與識别】Python、百度API一、百度API二、人臉識别

一、百度API

官網:http://ai.baidu.com/tech/face

官方文檔:http://ai.baidu.com/docs#/Face-Detect-V3/top

過程:1、建立應用;2、編寫程式;3、調用API。

【人臉檢測與識别】Python、百度API一、百度API二、人臉識别

二、人臉識别

# 官方文檔 http://ai.baidu.com/docs#/Face-Python-SDK/3d1dd00c
from aip import AipFace
import base64

'''建立應用'''
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client=AipFace(APP_ID,API_KEY,SECRET_KEY)

""" 
'''注冊'''
'''人臉檢測圖檔參數傳入'''
filepath='./image/anglebaby_1.jpg'
with open(filepath,'rb') as f:
    base64_data=base64.b64encode(f.read())
image =str(base64_data,'utf-8')
imageType='BASE64'
groupId = "group1"
userId = "anglebaby"
''' 調用人臉注冊 '''
result=client.addUser(image, imageType, groupId, userId);
print(result)
"""

'''調用人臉搜尋'''
filepath='./image/anglebaby_2.jpg'
with open(filepath,'rb') as f:
    base64_data=base64.b64encode(f.read())
image =str(base64_data,'utf-8')
imageType = "BASE64"
groupIdList = "group1"

'''搜尋'''
result=client.search(image, imageType, groupIdList)
print(result)
           

繼續閱讀