是這樣的我在利用百度api做一個人臉比對
源代碼如下
from aip import AipFace
""" 你的 APPID AK SK """
APP_ID = '18814618'
API_KEY = 'A1bFwZeTGWRlg5MDk4ycu24q'
SECRET_KEY = '186VKOrpAe0Lo1TtzPiTX5NjnExY7KCS'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
""" 讀取圖片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
images = [
get_file_content('D://001.jpg'),
get_file_content('D://002.jpg'),
]
""" 呼叫人臉比對 """
client.match(images);
""" 如果有可選引數 """
options = {}
options["ext_fields"] = "qualities"
options["image_liveness"] = ",faceliveness"
options["types"] = "7,13"
""" 帶引數呼叫人臉比對 """
result = client.match(images, options)
print (result)
錯誤提示
Object of type bytes is not JSON serializable

uj5u.com熱心網友回復:
images那邊要怎么寫
import base64
images = [
{'image': str(base64.b64encode(get_file_content('D://001.jpg')), 'utf-8'), 'image_type': 'BASE64'},
{'image': str(base64.b64encode(get_file_content('D://002.jpg')), 'utf-8'), 'image_type': 'BASE64'},
]
另外,你下面可選引數那段去了吧,現在傳引數也是放images里傳的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/75133.html
上一篇:求教!python怎么接收Esc鍵,就比如輸入完畢后按ESC結束輸入
下一篇:資料結構python
