【问题标题】:InvalidImageSize Microsoft Face API 1.0InvalidImageSize 微软人脸 API 1.0
【发布时间】: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


    【解决方案1】:

    您可以通过以下方式更改代码:

    with open("your-image.jpg", "rb") as imageFile:
      image = imageFile.read()
      conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
      conn.request("POST", "/face/v1.0/detect?%s" % params, headers=headers, body=image)
      response = conn.getresponse()
      data = response.read()
      print(data)
      conn.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 2017-05-04
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多