您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)python如何使用百度AI接口進(jìn)行人臉對比,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
注冊并提交申請。
創(chuàng)建應(yīng)用獲取AppID,API Key,Secret Key。
人臉對比 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)志 |
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()
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é)果:
照片加了模糊處理
關(guān)于“python如何使用百度AI接口進(jìn)行人臉對比”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。