文字识别【chinese_ocr_db_crnn】报错:'str' object has no attribute 'shape'
Created by: 670133189
报错内容:【'str' object has no attribute 'shape'】
版本、环境信息: chinese_ocr_db_crnn-1.0.0 paddlehub-1.7.1 paddlepaddle-1.8.1 MacOS-10.14.6 python-3.7.4
官方代码:
【1】启动PaddleHub Serving:
hub serving start -m chinese_ocr_db_crnn
【2】发送预测请求:
import requests
import json
import cv2
import base64
def cv2_to_base64(image):
data = cv2.imencode('.jpg', image)[1]
return base64.b64encode(data.tostring()).decode('utf8')
# 发送HTTP请求
data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/chinese_ocr_db_crnn"
r = requests.post(url=url, headers=headers, data=json.dumps(data))
# 打印预测结果
print(r.json()["results"])