如何使用Python将本地图像而不是URL发送到Microsoft Cognitive Face API(分析图像)? 在 [binary data] 正文中写些什么,以获取存储在计算机中的图像的情感。请提供完整的代码。
Here是我正在尝试的网站
这是我尝试过的:
url = "localhost:5000/";
data=open("C:/Users/Robot 2/Desktop/images/abc.bmp","rb")
requests.post(url,data=data)
response = requests.post(url, data=data)
答案 0 :(得分:0)
像这样:
faceapi_headers = {
# Request headers
'Content-type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': 'YourKey',
}
faceapi_params = urllib.urlencode({
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,glasses',
})
conn = httplib.HTTPSConnection('westeurope.api.cognitive.microsoft.com')
f = open(filename, "rb")
faceapi_body = f.read()
f.close()
conn.request("POST", "/face/v1.0/detect?%s" % faceapi_params, faceapi_body, faceapi_headers)
response = conn.getresponse()
data = response.read()