如何使用Python将本地图像而不是URL发送到Microsoft认知人脸API(分析图像(? 在[二进制数据]正文中写什么才能获得存储在计算机中的图像的情感。请提供完整的代码。
这是我正在尝试的网站
这是我尝试过的:
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)
像这样:
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()