gpt4 book ai didi

python - 如何使用 Microsoft Face API 识别集体照片中的人脸

转载 作者:太空宇宙 更新时间:2023-11-03 15:50:40 24 4
gpt4 key购买 nike

我想使用 Microsoft 的 Face API 识别一群人中的面孔。我已经阅读了他们的文档并编写了这段代码,但它没有按预期工作。它显示一些错误。

from projectoxford import Client,Face
print('----- Setting Environment to use Face API -----')
client = Client('MY API KEY')
personGroup = 'friends'
print('----- Uploading Sam -----')
storage.child('images/sam.jpg').put('/home/parth/Downloads/sam.jpg')
print('----- Done Uploading -----')
sam = storage.child('images/sam.jpg').get_url(token=None)
print(sam)
print('----- Uploading Dev -----')
storage.child('images/dev.jpg').put('/home/parth/Downloads/devansh.jpg')
print('----- Done Uploading -----')
dev = storage.child('images/dev.jpg').get_url(token=None)
print(dev)
print('----- Uploading Main -----')
storage.child('images/main.jpg').put('/home/parth/Downloads/main.jpg')
print('----- Done Uploading -----')
main = storage.child('images/main.jpg').get_url(token=None)
print(main)
print('----- Detecting Face Sam -----')
x = client.face.detect({'url': sam})
print(x)
sam_faceId = x[0]['faceId']
client.face.personGroup.createOrUpdate(personGroup, 'friends')
client.face.person.createOrUpdate(personGroup, [sam_faceId], 'Saumil')
client.face.personGroup.trainAndPollForCompletion(personGroup)
detectResults = client.face.detect({'url': main})
faceIds = []
for result in detectResults:
faceIds.append(result['faceId'])

'''
Identification Method
'''
identifyResults = client.face.identify(personGroup, faceIds)
for result in identifyResults:
for candidate in result['candidates']:
confidence = candidate['confidence']
personData = client.face.person.get(personGroup, candidate['personId'])
name = personData['name']
print('identified {0} with {1}% confidence'.format(name, str(float(confidence) * 100)))
client.face.personGroup.delete(personGroup)

现在它抛出了这个:

Traceback (most recent call last):
File "att3.py", line 55, in <module>
x = client.face.detect({'url': sam})
File "/usr/local/lib/python2.7/dist-packages/projectoxford/Face.py", line 56, in detect
return Base._postWithOptions(self, _detectUrl, options, params)
File "/usr/local/lib/python2.7/dist-packages/projectoxford/Base.py", line 87, in _postWithOptions
return Base._invoke(self, call)
File "/usr/local/lib/python2.7/dist-packages/projectoxford/Base.py", line 45, in _invoke
raise Exception('status {0}: {1}'.format(str(response.status_code), response.text))
Exception: status 404: { "statusCode": 404, "message": "Resource not found" }

我不知道为什么会出现这种情况。关于我做错了什么的任何解决方案或建议。

最佳答案

x = client.face.detect({'url': sam}) 正在尝试访问文字 url“url”,因为您将其作为字符串提供。我假设你打算用这个来代替:x = client.face.detect({main: sam}) 因为您调用了 get_url(token=None) 并将结果存储到 main 中> 变量。

关于python - 如何使用 Microsoft Face API 识别集体照片中的人脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41326929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com