在 Microsoft Cognitive Face 中创建人员组人员时出错 API
Error while creating person group person in microsoft cognitive face API
我有一个使用旧 API 的代码。我不知道新 API。知道的帮我修改一下代码
import cognitive_face as CF
from global_variables import personGroupId
import sqlite3
Key = '###################'
CF.Key.set(Key)
BASE_URL = 'https://region.api.cognitive.microsoft.com/face/v1.0/'
CF.BaseUrl.set(BASE_URL)
if len(sys.argv) is not 1:
res = CF.person.create(personGroupId, str(sys.argv[1])) #error line
print(res)
extractId = str(sys.argv[1])[-2:]
connect = sqlite3.connect("studentdb")
cmd = "SELECT * FROM Students WHERE id = " + extractId
cursor = connect.execute(cmd)
isRecordExist = 0
for row in cursor:
isRecordExist = 1
if isRecordExist == 1:
connect.execute("UPDATE Students SET personID = ? WHERE ID = ?",(res['personId'], extractId))
connect.commit()
connect.close()
如您所述,您使用的是旧版 API。您应该使用新的 API。请参阅 this(官方文档)以安装软件包和进一步参考。
包裹:
pip install --upgrade azure-cognitiveservices-vision-face
导入以下库(不包括其他基础库)
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
更新后的API命令如下:
res = face_client.person_group_person.create(person_group_id, str(sys.argv[1]))
除了Soorya上面回答的内容,对于想要示例代码参考的人,您可以在here
中查看最新的API示例代码
def build_person_group(client, person_group_id, pgp_name):
print('Create and build a person group...')
# Create empty Person Group. Person Group ID must be lower case, alphanumeric, and/or with '-', '_'.
print('Person group ID:', person_group_id)
client.person_group.create(person_group_id = person_group_id, name=person_group_id)
我有一个使用旧 API 的代码。我不知道新 API。知道的帮我修改一下代码
import cognitive_face as CF
from global_variables import personGroupId
import sqlite3
Key = '###################'
CF.Key.set(Key)
BASE_URL = 'https://region.api.cognitive.microsoft.com/face/v1.0/'
CF.BaseUrl.set(BASE_URL)
if len(sys.argv) is not 1:
res = CF.person.create(personGroupId, str(sys.argv[1])) #error line
print(res)
extractId = str(sys.argv[1])[-2:]
connect = sqlite3.connect("studentdb")
cmd = "SELECT * FROM Students WHERE id = " + extractId
cursor = connect.execute(cmd)
isRecordExist = 0
for row in cursor:
isRecordExist = 1
if isRecordExist == 1:
connect.execute("UPDATE Students SET personID = ? WHERE ID = ?",(res['personId'], extractId))
connect.commit()
connect.close()
如您所述,您使用的是旧版 API。您应该使用新的 API。请参阅 this(官方文档)以安装软件包和进一步参考。
包裹:
pip install --upgrade azure-cognitiveservices-vision-face
导入以下库(不包括其他基础库)
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
更新后的API命令如下:
res = face_client.person_group_person.create(person_group_id, str(sys.argv[1]))
除了Soorya上面回答的内容,对于想要示例代码参考的人,您可以在here
def build_person_group(client, person_group_id, pgp_name):
print('Create and build a person group...')
# Create empty Person Group. Person Group ID must be lower case, alphanumeric, and/or with '-', '_'.
print('Person group ID:', person_group_id)
client.person_group.create(person_group_id = person_group_id, name=person_group_id)