【发布时间】:2017-04-18 05:20:38
【问题描述】:
这个比我好尝试所有方法,例如将base64转换为二进制,只是不断在下面出现这个错误
{"error":{"code":"InvalidImageSize","message":"Image size
is too small or too big."}}
这是我的代码是用 python 编写的:
import httplib, urllib, base64
import json
import sys
import base64
# require for authentication
key = "YourKey"
# leave as one header so ther three steps can access the same format
# application/octet-stream
headers = {
# Request headers
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': key,
}
# params for detection return FaceId
params = urllib.urlencode({
# Request parameters
'returnFaceId': 'true',
})
with open("C://Python-Windows//random_test//unknowfaces//Adam.jpg", "rb") as
imageFile:
f = imageFile.read()
b = bytearray(f)
print f
#image_64_encode = base64.encodestring(image_read)
"""
body = {
"url":"https://lh6.googleusercontent.com/-
dKxIImkT0to/WApnOYQSIFI/AAAAAAAAAAA/H9IsZ2xGxiE/photo.jpg"
}
"""
#below is for the binary
body = {
f[0]
}
# conn to be use at all three steps
conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", "/face/v1.0/detect?%s" % params, str(body), headers)
response = conn.getresponse()
data = response.read()
print(data)
#Parse json data to print just faceId
somedata = json.loads(data)
faceid = somedata[0]['faceId']
print somedata[0]['faceId']
print " :is what face id has produce ==> " + faceid
conn.close()
不确定我是否在此踏板上正确使用了上述代码,因此请检查。
感谢您的支持,谢谢
【问题讨论】:
标签: python microsoft-cognitive