我有一个使用旧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。请参阅此(官方文档)以安装软件包和进一步参考。
包:
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]))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句