python 使用百度AI接口進行人臉對比的步驟
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 | 人臉的唯一標志 |
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接口進行人臉對比的步驟的詳細內(nèi)容,更多關(guān)于python 人臉對比的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Django csrf 兩種方法設(shè)置form的實例
今天小編就為大家分享一篇Django csrf 兩種方法設(shè)置form的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02詳解Python list 與 NumPy.ndarry 切片之間的對比
這篇文章主要介紹了詳解Python list 與 NumPy.ndarry 切片之間的區(qū)別的相關(guān)資料,list 切片返回的是不原數(shù)據(jù),對新數(shù)據(jù)的修改不會影響原數(shù)據(jù)而NumPy.ndarry 的切片返回的是原數(shù)據(jù)需要的朋友可以參考下2017-07-07python星號(*)和雙星號(**)?函數(shù)動態(tài)參數(shù)匹配及解包操作方法
這篇文章主要介紹了python星號(*)和雙星號(**)?函數(shù)動態(tài)參數(shù)匹配及解包操作,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03如何使用Flask-Migrate拓展數(shù)據(jù)庫表結(jié)構(gòu)
這篇文章主要介紹了如何使用Flask-Migrate拓展數(shù)據(jù)庫表結(jié)構(gòu),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-07-07Python使用MYSQLDB實現(xiàn)從數(shù)據(jù)庫中導出XML文件的方法
這篇文章主要介紹了Python使用MYSQLDB實現(xiàn)從數(shù)據(jù)庫中導出XML文件的方法,涉及Python使用MYSQLDB操作數(shù)據(jù)庫及XML文件的相關(guān)技巧,需要的朋友可以參考下2015-05-05Django發(fā)送郵件和itsdangerous模塊的配合使用解析
這篇文章主要介紹了Django發(fā)送郵件和itsdangerous模塊的配合使用解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-08-08