用于Python的Microsoft Emotion API - 从内存上传视频

时间:2016-10-22 23:59:39

标签: python python-2.7 microsoft-cognitive

我正在尝试将视频加载到Microsoft的Emotion API。到目前为止,这是我的代码:

JFrame frame = new JFrame();
JLabel label = new JLabel(); //or JPanel if that's what you prefer
ImageIcon equil = new ImageIcon("filepath/to/this/image");
ImageIcon escal = new ImageIcon("filepath/to/this/image");
ImageIcon isosc = new ImageIcon("filepath/to/this/image");
frame.add(label);
switch(t) {
        default: {
            label.setIcon(null);
        }

        case "Equilatero": {
            label.setIcon(equil);
        }

        case "Escaleno": {
            label.setIcon(escal);
        }

        case "Isosceles": {
            label.setIcon(isosc);
        }
    }

我正在收回HTTP状态代码202,所以我认为我正在做大部分事情。但是,当我等待大约2分钟然后输入

import httplib
import urllib
import base64
import json
import pandas as pd
import numpy as np
import requests

_url = 'https://api.projectoxford.ai/emotion/v1.0/recognizeInVideo'
_key = '<my key>'
_maxNumRetries = 10

paramsPost = dict()
paramsPost['outputStyle'] = 'perFrame'

headersPost = dict()
headersPost['Ocp-Apim-Subscription-Key'] = _key
headersPost['content-type'] = 'application/octet-stream'
jsonGet = {}
headersGet = dict()
headersGet['Ocp-Apim-Subscription-Key'] = _key
paramsGet = urllib.urlencode({})

responsePost = requests.request('post', _url, \
                                data = {'file':open('my_file.mp4','rb').read()}, \
                                headers = headersPost, params = paramsPost)

print responsePost.status_code

,...我回来了#34;失败&#34;。我做错了什么?

编辑:我找到了自己问题的答案。由于关于Emotion API的文档很少,我将在下面与大家分享我的发现,以达到社区的最佳利益。 以下代码返回HTML状态代码202,并成功上传本地驱动器中的视频:

getResponse = requests.request('get', videoIDLocation, json = jsonGet,\
                               data = None, headers = headersGet, params = paramsGet)

print json.loads(getResponse.text)['status']

0 个答案:

没有答案