Azure Recognition返回空结果

时间:2019-05-27 21:01:51

标签: azure ocr

我已经使用OCR API已有一段时间了,但是我想看看ognizeText API是否提高了性能。问题在于,调用ognizeText API只会返回一个空字符串。

如果我将API调用更改为/vision/v2.0/ocr,则一切正常。

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/octet-stream',
    'Ocp-Apim-Subscription-Key': 'MYAPIKEY',
}

params = urllib.parse.urlencode({
    # Request parameters
    'mode': 'Printed',
})


with open(filename, 'rb') as f:
    data_image = f.read()


try:
    conn = http.client.HTTPSConnection('canadacentral.api.cognitive.microsoft.com')
    conn.request("POST", "/vision/v2.0/recognizeText?%s" % params, data_image, headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

1 个答案:

答案 0 :(得分:0)

请务必阅读API规范:https://westus.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/587f2c6a154055056008f200

API仅返回202接受(如果您的请求有效)。这包括一个包含URL的标头 Operation-Location 。您随后对该URL发出了请求,以检索请求的状态/结果。