百度api實現人臉對比

2022-05-06 15:24:14 字數 1358 閱讀 6382

第一步(註冊賬號):

如圖:

第二步(**):

import

requests

import

base64

import

json

#1,準備好申請的人臉識別api,api key, secret key

api1="

你的id &client_secret=你的secret key"#

api2=""

#2,獲取token值,拼接api

defget_token():

response=requests.get(api1)

access_token=eval(response.text)['

access_token']

api2="

"+"?access_token=

"+access_token

return

api2

#3,讀取資料

defread_img(img1,img2):

with open(img1,'rb

') as f:

pic1=base64.b64encode(f.read())

with open(img2,'rb

') as f:

pic2=base64.b64encode(f.read())

params=json.dumps([,])

return

params

#4,發起請求拿到對比結果

defanalyse_img(file1,file2):

params=read_img(file1,file2)

api=get_token()

content=requests.post(api,params).text

#print(content)

score=eval(content)['

result

']['

score']

if score>80:

print('

識別相似度度為

'+str(score)+'

%,是同一人')

else

:

print('

識別相似度度為

'+str(score)+'

%,不是同一人')

")

只要在同級目錄下放上img1.jpg 和 img2.jpg 即可!

python 使用百度API實現人臉對比識別

使用pip安裝 api key 你的 api key secret key 你的secret key def fileopen filepath 開啟 with open filepath,rb as f data base64.b64encode f.read image str data,utf...

Python使用百度api做人臉對比

pip install baidu aip如果在pycharm裡也可以在setting project interpreter 右邊綠色加號,輸入baidu,安裝baidu aip 之後把得到的api key secretkey 填進去。from aip import aipface api key...

百度API連線

1 使用api key和secret key獲取token 2 連線呼叫方法。1 獲取token。public static string getauth 獲取api訪問token 該token有一定的有效期,需要自行管理,當失效時需重新獲取.return assess token 示例 對位元組陣...