基于PaddleOCR2.7.0发布WebRest服务测试案例
#WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
#警告:这是一个开发服务器。不要在生产部署中使用它。请改用生产WSGI服务器。
输出结果:
'''
输出结果
[
"中华人民共和国,0.9899783730506897",
"居民身份证,0.9980843663215637",
"祥证,0.8810203075408936",
"正,0.9998733997344971",
"签发机关北京市公安商西城分局,0.9768146872520447",
"有效期限2004.10.27-2024.10.26,0.9777843952178955",
"姓名金阳,0.9970041513442993",
"反,0.8982676267623901",
"性别女,0.9921286702156067",
"民族汉,0.7694575190544128",
"出生1978年10月27日,0.9945864081382751",
"住址北京市西城区复兴门外大,0.9793714284896851",
"街999号院11号楼3单元,0.997355043888092",
"样证502室,0.954838752746582",
"公民身份号码,0.999056339263916",
"110102197810272321,0.9936114549636841",
"头杀@刘海波,0.8078877925872803"
]
'''
postman请求格式:
访问地址:http://127.0.0.1:5000/ocr post模式 参数image_path
postman 请求格式
Json格式和 image_path=
'''
{
"image_path" : "E:/project/python/OCR/data/sfz.jpg"
}
'''
安装paddleocr2.7.0
激活环境
conda activate d:\programdata\conda\cwgis
conda deactivate
采用pip模式查询包的版本列表情况
pip index versions paddleocr
pip install paddleocr==2.7.0
#兼容性再安装
pip install opencv-python==4.4.0.46
pip install click==8.1.3
conda install pillow==9.0.1
PaddleOCR版本列表情况
C:\Users\hsgpc>pip index versions paddleocr
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
paddleocr (2.7.0.2)
Available versions: 2.7.0.2, 2.7.0.1, 2.7.0.0, 2.6.1.3, 2.6.1.2, 2.6.1.1, 2.6.1.0, 2.6.0.3, 2.6.0.2, 2.6.0.1, 2.6, 2.5.0.3, 2.5.0.2, 2.5, 2.4.0.4, 2.4.0.3, 2.4.0.2, 2.4.0.1, 2.4, 2.3.0.2, 2.3.0.1, 2.3, 2.2.0.2, 2.2.0.1, 2.2, 2.0.6, 2.0.5, 2.0.4, 2.0.3, 2.0.2, 2.0.1, 1.1.1, 1.0.1, 1.0.0, 0.0.3.1, 0.0.3, 0.0.2, 0.0.1.1
C:\Users\hsgpc>
测试的发布服务的代码:文章来源:https://www.toymoban.com/news/detail-673492.html
from flask import Flask, request, jsonify
from paddleocr import PaddleOCR
#报错:ImportError: cannot import name 'ParameterSource' from 'click.core'
#pip index versions click #查看版本号列表
#随机选择一个版本8.0.0版本,安装时提示flask 2.3.2 requires click>=8.1.3,
#故再次选择安装8.1.3版本 OK
#pip install click==8.1.3
# need to run only once to download and load model into memory
p = PaddleOCR(use_angle_cls=True, lang="ch")
print(__name__) #__main__
app = Flask(__name__)
#定义 get 方法 /v
@app.route('/v', methods=['get'])
def v():
return "1.0.0"
#定义 post 方法 /ocr
@app.route('/ocr', methods=['POST'])
def ocr():
data = request.get_json()
image_path = data['image_path'] # 从请求中获取图像路径
print('image_path=',image_path)
#ocr_result = PaddleOCR.ocr(image_path, use_gpu=False) # 调用PaddleOCR模型进行图像识别
ocr_result = p.ocr(image_path, cls=True)
h_result=[]
index=1
for line in ocr_result:
for detection in line:
t=detection[1][0]+","+str(detection[1][1])
h_result.append(t)
index+=1
return jsonify(h_result) # 将识别结果以JSON格式返回给客户端
if __name__ == '__main__':
app.run()
#http://127.0.0.1:5000/v #OK
本blog地址:https://blog.csdn.net/hsg77
—the—end—文章来源地址https://www.toymoban.com/news/detail-673492.html
到了这里,关于基于PaddleOCR2.7.0发布WebRest服务测试案例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!