python 使用百度AI接口進(jìn)行人臉對比的步驟
注冊百度智能云,提交申請。
創(chuàng)建應(yīng)用獲取AppID,API Key,Secret Key。
2. 安裝baidu python api人臉對比 API 文檔
pip install baidu-aip
調(diào)用:
import base64from aip import AipFaceAPP_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 cv2cap = 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 cv2import base64from aip import AipFaceAPP_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ù)器錯(cuò)誤’)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)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲2. jsp+servlet簡單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))3. JavaScript實(shí)現(xiàn)組件化和模塊化方法詳解4. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息5. HTML5 Canvas繪制圖形從入門到精通6. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法7. 淺談SpringMVC jsp前臺獲取參數(shù)的方式 EL表達(dá)式8. SpringMVC+Jquery實(shí)現(xiàn)Ajax功能9. ASP中if語句、select 、while循環(huán)的使用方法10. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明
