用于Python视频的Microsoft Emotion API
问题描述:
我使用下面的代码发送视频,显然我没有错误。但是,这个回应即将变成空白。我如何阅读回复?用于Python视频的Microsoft Emotion API
########### Python 2.7 #############
import httplib, urllib, base64, json
headers = {
# Request headers
'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
}
video_filename = {"url":"https://fsarquivoeastus.blob.core.windows.net/public0/WhatsApp-Video-20160727.mp4"}
params = urllib.urlencode({})
try:
conn = httplib.HTTPSConnection('api.projectoxford.ai')
conn.request("POST", "/emotion/v1.0/recognizeinvideo?%s" % params, json.dumps(video_filename), headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
答
认知服务视频API(包括Emotion)异步运行,并且在POST成功时返回空响应主体。你必须做什么,而不是从标题检索操作URL,如下所示:
response = conn.getresponse()
location = response.getheader('operation-location');
print(location);
你叫GET对location
URL来检查操作的状态。更多关于here。
答
@FelipeSouzaLima,要从视频中的情感识别中获得操作结果,需要执行以下两个步骤。
调用REST API为Emotion Recognition in Video,那么你会得到空白响应主体和
operation-location
头,这将在下一步的@cthrash说被调用。调用上面的
operation-location
头的值的url,使用与请求头相同的Ocp-Apim-Subscription-Key
,然后您可以获得包含识别作业状态的json响应主体。如果json响应中的status
字段的值为Succeeded
,那么您将在json结果中获得processingResult
字段的运算结果,请参阅Get Recognition in Video Operation Result的REST API。