2016-08-03 17 views
0

我使用下面的代碼發送視頻,顯然我沒有錯誤。但是,這個迴應即將變成空白。我如何閱讀回覆?用於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)) 

回答

1

認知服務視頻API(包括Emotion)異步運行,並且在POST成功時返回空響應主體。你必須做什麼,而不是從標題檢索操作URL,如下所示:

response = conn.getresponse() 
location = response.getheader('operation-location'); 
print(location); 

你叫GET對location URL來檢查操作的狀態。更多關於here

0

@FelipeSouzaLima,要從視頻中的情感識別中獲得操作結果,需要執行以下兩個步驟。

  1. 調用REST API爲Emotion Recognition in Video,那麼你會得到空白響應主體和operation-location頭,這將在下一步的@cthrash說被調用。

  2. 調用上面的operation-location頭的值的url,使用與請求頭相同的Ocp-Apim-Subscription-Key,然後您可以獲得包含識別作業狀態的json響應主體。如果json響應中的status字段的值爲Succeeded,那麼您將在json結果中獲得processingResult字段的運算結果,請參閱Get Recognition in Video Operation Result的REST API。

相關問題