python 使用百度AI接口進(jìn)行人臉對比的步驟
1. 注冊百度云賬號
注冊百度智能云,提交申請。
創(chuàng)建應(yīng)用獲取AppID,API Key,Secret Key。
2. 安裝baidu python api
人臉對比 API 文檔
pip install baidu-aip
調(diào)用:
import base64
from aip import AipFace
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
result = client.match([
{
'image': str(base64.b64encode(open('D:/chenjy/1.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
},
{
'image': str(base64.b64encode(open('D:/chenjy/2.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
}
])
print(result)
返回值:

返回主要參數(shù)說明:
| 參數(shù)名 | 必選 | 類型 | 說明 |
|---|---|---|---|
| score | 是 | float | 人臉相似度得分,推薦閾值80分 |
| face_list | 是 | array | 人臉信息列表 |
| face_token | 是 | string | 人臉的唯一標(biāo)志 |
3.調(diào)用攝像頭
import cv2
cap = cv2.VideoCapture(0) # 打開攝像頭
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2.imshow('window', frame)
cv2.imwrite('D:/chenjy/2.png', frame) # 保存路徑
cv2.waitKey(2000)
cap.release()
cv2.destroyAllWindows()
4.完整測試程序
import cv2
import base64
from aip import AipFace
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
def get_result():
result = client.match([
{
'image': str(base64.b64encode(open('D:/chenjy/1.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
},
{
'image': str(base64.b64encode(open('D:/chenjy/2.png', 'rb').read()), 'utf-8'),
'image_type': 'BASE64',
}
])
if result['error_msg'] == 'SUCCESS':
score = result['result']['score']
print(result)
print('相似度:'+str(score))
else:
print('服務(wù)器錯誤')
cap = cv2.VideoCapture(0) # 打開攝像頭
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2.imshow('window', frame)
cv2.imwrite('D:/chenjy/2.png', frame) # 保存路徑
cv2.waitKey(2000)
get_result()
cap.release()
cv2.destroyAllWindows()
結(jié)果:
照片加了模糊處理


以上就是python 使用百度AI接口進(jìn)行人臉對比的步驟的詳細(xì)內(nèi)容,更多關(guān)于python 人臉對比的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python通過pillow識別動態(tài)驗證碼的示例代碼
在上網(wǎng)時,經(jīng)常會遇到驗證碼,本次試驗將帶領(lǐng)大家認(rèn)識驗證碼的一些特性,并利用 Python 中的 pillow 庫完成對驗證碼的破解。感興趣的可以了解一下2021-11-11
python中使用ctypes調(diào)用so傳參設(shè)置遇到的問題及解決方法
這篇文章主要介紹了python中使用ctypes調(diào)用so傳參設(shè)置,本文較詳細(xì)的給大家介紹了遇到問題及解決方案,需要的朋友可以參考下2019-06-06
Python 3.x基于Xml數(shù)據(jù)的Http請求方法
今天小編就為大家分享一篇Python 3.x基于Xml數(shù)據(jù)的Http請求方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
如何徹底解決Python中matplotlib不顯示中文的問題詳解(顯示方框)
Matplotlib繪制圖像顯示中文的時候,中文會變成小方格子,下面這篇文章主要給大家介紹了關(guān)于如何徹底解決Python中matplotlib不顯示中文問題的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04
使用Python和GDAL給圖片加坐標(biāo)系的實現(xiàn)思路(坐標(biāo)投影轉(zhuǎn)換)
這篇文章主要介紹了使用Python和GDAL給圖片加坐標(biāo)系的實現(xiàn)思路(坐標(biāo)投影轉(zhuǎn)換),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
50行Python代碼實現(xiàn)視頻中物體顏色識別和跟蹤(必須以紅色為例)
本文通過50行Python代碼實現(xiàn)視頻中物體顏色識別和跟蹤效果,通過實例截圖和實例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下2019-11-11
一起來學(xué)習(xí)一下python的數(shù)據(jù)類型
這篇文章主要為大家詳細(xì)介紹了python的數(shù)據(jù)類型,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下希望能夠給你帶來幫助2022-01-01

