0

我正在尝试使用kairos API 进行人脸检测。我有以下 python 代码。但是,我收到一个错误:

img1.jpg
================RESPONSE=====================
b'{\n\t"Errors": [\n\t\t{\n\t\t\t"ErrCode": 1003,\n\t\t\t"Message": "gallery_name is not a valid parameter"\n\t\t},\n\t\t{\n\t\t\t"ErrCode": 1003,\n\t\t\t"Message": "subject_id is not a valid parameter"\n\t\t}\n\t]\n}'
-1

我的代码:

#!/usr/bin/python3

import requests
import io
import http.client
import base64
import json
import glob, os
from os.path import basename

dir_path = "/home/Photos/" 
path = "/home/Kairos/kairos_jason/"

os.chdir(dir_path)

for file in glob.glob("*.jpg"):
    img_path = file
    print(img_path)
    files = {'image': (img_path, open(dir_path + img_path, 'rb'), 'image/jpg', {'Expires': '0'})}

    headers = {
        'app_id': "My_Id",
        'app_key': "My_Key",
    }

    values_enrol = {
       "subject_id" : "11",
       "gallery_name" : "msc_galary"
    }

    res = requests.post('https://api.kairos.com/detect', headers=headers, files=files, data=values_enrol)

    print("================RESPONSE=====================")
    print(res.content)
    strRes = str(res.content)

    print(strRes.find("face_id"))
    with open(path + os.path.splitext(img_path)[0] + ".txt" , 'w') as outfile:
        outfile.write(str(res.content))
4

1 回答 1

2

/detect网址不接受任何gallery_name

但是,gallery_name以下网址中需要:

  • /gallery/view
  • /gallery/remove
  • /gallery/remove_subject
  • /gallery/view_subject

鉴于您的数据还包括 a subject_id,很明显您需要将请求重写为/view_subjecturl

res = requests.post('https://api.kairos.com/gallery/view_subject', headers=headers, files=files, data=values_enrol)

于 2018-01-05T11:18:24.873 回答