说明
使用PaddleOCR实现银行卡号识别,训练数据集中有银行卡图片,以及标注的银行卡卡号和卡号的坐标位置
文档:https://aistudio.baidu.com/aistudio/projectdetail/4459116
github:https://github.com/PaddlePaddle/PaddleOCR
过程
1. 安装PaddleOCR
https://github.com/PaddlePaddle/PaddleOCR
2. 安装推理模型
三个包下载解压到目录inference
3. 训练-测试-模型导出
# GPU训练
python -m paddle.distributed.launch --gpus 0 tools/train.py -o Global.use_visualdl=True -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0_bank.yml
# 测试
python tools/infer_det.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0_bank.yml -o Global.pretrained_model="./output/ch_db_mv3_bank/best_accuracy" Global.inf er_img=D:\bank1.jpg PostProcess.unclip_ratio=2.5
# 模型导出
python tools/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0_bank.yml -o Global.pretrained_model="./output/ch_db_mv3_bank/best_accuracy" Global.save_inference_dir="./inference/ch_db_mv3_bank/"
参考文章:https://blog.csdn.net/YY007H/article/details/120646395
4. 启动服务
hub serving start -m ocr_system
启动后
warnings.warn("Setuptools is replacing distutils.")
[2022-12-30 14:07:45,763] [ WARNING] - The _initialize method in HubModule will soon be deprecated, you can use the __init__() to handle the initialization of the object
* Serving Flask app 'paddlehub.serving.app_compat'
* Debug mode: off
INFO 2022-12-30 14:07:46,727 _internal.py:224] WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8866
使用
1. 内置工具发送数据
python tools/test_hubserving.py --server_url http://127.0.0.1:8866/predict/ocr_system --image_dir /bank1.jpg
响应数据
----------------------------
[2022/12/30 15:18:51] ppocr INFO: Predict time of /bank1.jpg: 0.970s
[2022/12/30 15:18:51] ppocr INFO: [{'confidence': 0.9465084075927734, 'text': '6217003810026896707', 'text_region': [[59, 155], [368, 143], [369, 161], [60, 172]]}]
[2022/12/30 15:18:51] ppocr INFO: avg time cost: 0.9703464508056641
----------------------------
6217003810026896707是识别后的银行卡卡号
2. 使用postman发送请求
先将银行卡图片转成base64,然后发送post请求即可