1

我想使用 Microsoft 的人脸 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)

现在它throws这个:

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" }

我不知道为什么会发生。关于我做错了什么的任何解决方案或建议。

4

1 回答 1

1

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

于 2016-12-26T06:09:23.540 回答