如何使用Python将本地图像(而不是URL)发送到microsoftcognitive Face API(分析图像)?

2024-10-02 06:35:37 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用Python将本地图像(而不是URL)发送到microsoftcognitive Face API(分析图像)? 在[二进制数据]身体中写入什么来获得存储在计算机中的图像的情感。请提供完整代码。在

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)

Tags: 数据代码图像apiurldata计算机二进制
1条回答
网友
1楼 · 发布于 2024-10-02 06:35:37

像这样:

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()

相关问题 更多 >

    热门问题