我正在使用 Microsoft Azures Vision API 来识别本地 JPEG 图像中的手写文本。我正在编辑 Microsoft 的源代码,以允许从本地源而不是从 URL 识别图像。但是,我不确定如何处理此错误:“TypeError:字节类型的对象不是 JSON 可序列化的”。
image_path = "/Users/FelixWallis/Downloads/IMG_2430.jpg"
image_data = open(image_path, "rb").read()
headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params = {'mode': 'Handwritten'}
response = requests.post(
text_recognition_url, headers=headers, params=params, json=image_data)
response.raise_for_status()
operation_url = response.headers["Operation-Location"]
analysis = {}
poll = True
while (poll):
response_final = requests.get(
response.headers["Operation-Location"], headers=headers)
analysis = response_final.json()
time.sleep(1)
if ("recognitionResult" in analysis):
poll= False
if ("status" in analysis and analysis['status'] == 'Failed'):
poll= False
polygons=[]
if ("recognitionResult" in analysis):
# Extract …
Run Code Online (Sandbox Code Playgroud)