我有一个使用较旧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(官方文档)以获取软件包的安装和更多参考。
PACKAGE:
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示例代码>
here