0
votes

I have a question about the input in Emotion API. I want to use it in real time so the purpose is to send a binary array ( my image data) every 5 seconds.

My question is, is that possible to send directly my binary array or I have to create and save an image in my disk in specific file like PNG, JPEG, ... and then send it to Microsoft API?

If we it's possible to send something else than JPEG, PNG,... do you have any idea how I can do it in Python 2.7? headers['Content-Type'] = 'application/json' or headers['Content-Type'] = 'application/octet-stream'

Thank you for your help, Camille

1

1 Answers

0
votes

For Python, you'd want something like this:

import requests
with open('your-file.jpg', 'rb') as f:
   headers['Ocp-Apim-Subscription-Key'] = 'YOUR-KEY'
   headers['Content-Type'] = 'application/octet-stream'
   req = requests.post('https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize', headers=headers, data=f)
req.json()

In that example, it uses a file, but it can just as easily be an in-memory buffer, so long as the format is understood.

You might be interested to know that there's a sample application that calls the service periodically. It is, however, in C#, which may not work for you. The sample app has the advantage that it employs basic face rectangle detection on the client using OpenCV, thus making fewer network requests to Microsoft Cognitive Services.