PaddleOCR加载chinese_ocr_db_crnn_server/chinese_ocr_db_crnn_modile模型进行中英文混合预测(代码)实践

1. 环境搭建

参考:《PaddleOCR加载chinese_ocr_db_crnn_server模型进行中英文混合预测(命令行)实践

2. 代码
import paddlehub as hub
import cv2


# 待预测图片
test_img_path = ["./pic/0-1.jpg"]


def predict():
	# 选择chinese_ocr_db_crnn_server模型
    ocr = hub.Module(name="chinese_ocr_db_crnn_server")
    # 选择chinese_ocr_db_crnn_mobile模型
    # ocr = hub.Module(name="chinese_ocr_db_crnn_mobile")
    np_images = [cv2.imread(image_path) for image_path in test_img_path]
    results = ocr.recognize_text(
        images=np_images,  # 图片数据,ndarray.shape 为 [H, W, C],BGR格式;
        use_gpu=False,  # 是否使用 GPU;若使用GPU,请先设置CUDA_VISIBLE_DEVICES环境变量
        output_dir='ocr_result',  # 图片的保存路径,默认设为 ocr_result;
        visualization=True,  # 是否将识别结果保存为图片文件;
        box_thresh=0.5,  # 检测文本框置信度的阈值;
        text_thresh=0.5)  # 识别中文文本置信度的阈值;
    for result in results:
        data = result['data']
        save_path = result['save_path']
        for infomation in data:
            print('text: ', infomation['text'], '\nconfidence: ', infomation['confidence'], '\ntext_box_position: ',
                  infomation['text_box_position'])


if __name__ == '__main__':
    # show_img()
    predict()


关于模型的几点说明:
OCR根据应用场景可以大致分成“特定场景下的专用OCR”以及“多种场景下的通用OCR”。
专用OCR - 可以针对特定场景进行设计、优化以达到最好的特定场景下的效果展示,证件识别以及车牌识别就是专用OCR的典型案例。
通用OCR - 就是使用在更多、更复杂的场景下,拥有比较好的泛性。在这个过程中由于场景的不确定性,比如:图片背景极其丰富、亮度不均衡、光照不均衡、残缺遮挡、文字扭曲、字体多样等等问题,会带来极大的挑战。

这一套模型属于专用OCR,又分为:
(1)精简版,即chinese_ocr_db_crnn_mobile(inference模型大小约5.4MB);
(2)高精度版,即chinese_ocr_db_crnn_server(inference模型大小约105MB)。
该模型支持(1)中英文数字组合识别、(2)竖排文字识别、(3)长文本识别。且只支持“一键识别”,我的理解就是像全自动傻瓜相机一样:不需要也不支持参数调节。
实测结果显示,精简版能达到和高精度版几乎相同的预测准确性,运算耗时大约为后者的一半。

3. 预测结果

在这里插入图片描述
在这里插入图片描述
E:\test\PycharmProjects\PaddleStudy2\venv\Scripts\python.exe E:/test/PycharmProjects/PaddleStudy2/main.py
E:\test\PycharmProjects\PaddleStudy2\venv\lib\site-packages\pip_vendor\packaging\version.py:127: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
warnings.warn(
E:\test\PycharmProjects\PaddleStudy2\venv\lib\site-packages\pip_vendor\packaging\version.py:127: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release
warnings.warn(
[2021-03-16 09:24:40,232] [ WARNING] - The _initialize method in HubModule will soon be deprecated, you can use the __init__() to handle the initialization of the object
[2021-03-16 09:24:41,158] [ WARNING] - The _initialize method in HubModule will soon be deprecated, you can use the __init__() to handle the initialization of the object
text: 双耳机配对
confidence: 0.9995235204696655
text_box_position: [[64, 63], [301, 69], [299, 119], [63, 113]]
text: 首次配对方法:
confidence: 0.9997860193252563
text_box_position: [[71, 186], [336, 194], [334, 232], [70, 225]]
text: 1、取出两只耳机,再将两只耳机放回充电盒中
confidence: 0.9993939399719238
text_box_position: [[67, 245], [767, 258], [767, 297], [67, 283]]
text: (此步骤为新机激活)
confidence: 0.9379152655601501
text_box_position: [[116, 293], [411, 300], [410, 335], [115, 328]]
text: 2、再次取出两只耳机
confidence: 0.999390721321106
text_box_position: [[67, 339], [401, 349], [399, 384], [66, 374]]
text: 3、刷新手机蓝牙设备列表,点击配对QCY-T1C,完成配对
confidence: 0.9993934035301208
text_box_position: [[67, 388], [937, 402], [937, 437], [67, 422]]
text: 耳机取出会自动开机,若未自动开机,请充电后重新尝试
confidence: 0.990841269493103
text_box_position: [[80, 436], [938, 451], [938, 483], [80, 468]]
text: 切换设备配对方法:
confidence: 0.9996602535247803
text_box_position: [[71, 536], [421, 536], [421, 573], [71, 573]]
text: 1、关闭A手机蓝牙,耳机自动断开进入配对模式
confidence: 0.9853517413139343
text_box_position: [[67, 590], [791, 598], [791, 636], [67, 629]]
text: 2、刷新B手机蓝牙设备列表,点击配对QCY-T1C,完成配对
confidence: 0.9961883425712585
text_box_position: [[63, 638], [964, 649], [964, 695], [63, 684]]
text: *不支持同时连接两台手机,下次开机默认回连上次配对的手机
confidence: 0.9984445571899414
text_box_position: [[73, 686], [989, 698], [989, 748], [73, 736]]
text: 双耳机配对
confidence: 0.9994222521781921
text_box_position: [[68, 61], [310, 74], [306, 124], [65, 112]]
text: 首次配对方法:
confidence: 0.9997161030769348
text_box_position: [[76, 187], [342, 194], [341, 233], [75, 226]]
text: 1、取出两只耳机,再将两只耳机放回充电盒中
confidence: 0.9952978491783142
text_box_position: [[71, 245], [772, 257], [772, 297], [71, 285]]
text: (此步骤为新机激活)
confidence: 0.9479562640190125
text_box_position: [[121, 294], [417, 300], [417, 337], [121, 331]]
text: 2、再次取出两只耳机
confidence: 0.958042323589325
text_box_position: [[72, 343], [407, 350], [407, 382], [72, 374]]
text: 3、刷新手机蓝牙设备列表,点击配对QCY-T1C,完成配对
confidence: 0.9990030527114868
text_box_position: [[71, 389], [941, 398], [941, 435], [71, 425]]
text: 耳机取出会自动开机,若未自动开机,请充电后重新尝试
confidence: 0.9989553689956665
text_box_position: [[85, 438], [942, 446], [942, 479], [85, 471]]
text: 切换设备配对方法:
confidence: 0.9995059967041016
text_box_position: [[75, 536], [428, 536], [428, 575], [75, 575]]
text: 1、关闭A手机蓝牙,耳机自动断开进入配对模式
confidence: 0.9949502944946289
text_box_position: [[75, 595], [800, 595], [800, 630], [75, 630]]
text: 2、、刷新B手机蓝牙设备列表,点击配对QCY-T1C,完成配对
confidence: 0.988647997379303
text_box_position: [[68, 641], [966, 643], [966, 687], [68, 685]]
text: *不支持同时连接两台手机,下次开机默认回连上次配对的手机
confidence: 0.9987525343894958
text_box_position: [[76, 689], [990, 692], [990, 739], [76, 736]]
text: 不支持同时连接两台手机
confidence: 0.9991649389266968
text_box_position: [[7, 4], [369, 4], [369, 28], [7, 28]]
text: 不支持同时连接两台手机
confidence: 0.9984502196311951
text_box_position: [[7, 5], [371, 3], [371, 27], [7, 30]]
text: then
confidence: 0.9547896385192871
text_box_position: [[9, 7], [142, 7], [142, 63], [9, 63]]
text: tr
confidence: 0.7379519939422607
text_box_position: [[331, 13], [391, 23], [389, 65], [329, 52]]
text: agair
confidence: 0.988548755645752
text_box_position: [[423, 7], [586, 2], [586, 76], [423, 81]]
W0316 09:24:40.241915 16684 analysis_predictor.cc:1145] Deprecated. Please use CreatePredictor instead.
Process finished with exit code 0

4. 更多效果展示

图1:在这里插入图片描述
在这里插入图片描述
text: 宁波高尔节能科技有限公司
text: GAOER
text: 冷冻式干燥机
text: 型号GEAD-6F
text: 环境温度≤38℃入口温度<80℃空气处理量6.5m3
text: 压力露点2°C~10℃电流5.5A
text: 额定工作压力<1MPa
text: 冷媒R22
text: 功率1.228kw
text: 电源220V/50Hz
text: 重量
text: 外形尺寸880X550X1025
text: 出厂编号
text: 出厂日期
text: 浙江宁波溪口工业区综研路30-1号

图2:在这里插入图片描述
在这里插入图片描述
text: 中国北汽银翔汽车有限公司制造
text: VIN:LNBMDBAANGU091086
text: 品牌北京牌
text: 整车型号BJ6450BLV1Z
text: 最大净功率70.5kW
text: 发动机型号BJ415A
text: 最大允许总质量1925kg
text: 发动机排量1500ml
text: 制造年月2
text: 2016年5月
text: 乘员数

图3:在这里插入图片描述
在这里插入图片描述
text: ZNO5A
text: 号:
text: 选线路数:
text: 型
text: kY
text: 外壳防护等级
text: 额定电压:
text: Hz
text: 50
text: 电抗器额定功率
text: 额定频率:
text: 年
text: 20
text: 期:
text: 制造日
text: 月
text: 出厂编号:
text: RH
text: 产品综合:Q/PY)ZNDL1-2006标准
text: 传真:020-34811741
text: 020-22883341.22883254.22883741
text: 网址:
text: 联系电话:
text: www.nzhdl.com
text: 邮编:
text: zaonet@126.com
text: 电子邮箱:
text: 511400
text: 地
text: 址:广州市番昌迎宾路730号天安科技园创新821

图4:
在这里插入图片描述
在这里插入图片描述
text: 厦门赛恩机电科技有限公司
text: 电话:0592-5784545 5774549
text: 13606903002
text: 制造日期:2010年

【参考文档】
PaddleHub一键OCR中文识别

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
受到大佬项目 免root跨平台自动化测试框架webrebot 本地离线OCR的启发和指引,成功的把百度开源的 PaddleOCR 应用到PYTHON及VC++ 经过小范围测试python的效果比VC++理想很多,绝大多数游戏及日常都可以成功通用识别. 更新添加DLL版本了 在网盘里已经更新了VC++的 DLL版本,及VC++调用测试的!知道易语言 怎么调用64位DLL的也发个例子吧 注: PYTHON代码里还用到了两个组件要在按下面的安装完成PaddlePaddlePaddleOCR后再执行两个命令才能使用 fastapi 一个异步的超强WEB框架 1、python -m pip install fastapi 2、python -m pip install uvicorn 游戏小图识别成功率比较高 大图测试 python部分代码: python 的安装很多的坑..在期间找了无数贴子。。自己把经验总结分享 一、安装python         安装3.7或者3.8 python         我的安装环境是 WIN10 X64 PYTHON 3.85 二、安装PaddlePaddle 升级PIP  python -m pip install --upgrade pip         如果您的机器安装的是CUDA9或CUDA10,请运行以下命令安装         python -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple         如果您的机器是CPU,请运行以下命令安装, 工作室或者GPU不太好的就用这个, 正常也使用这个就好了         python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple 三、克隆\安装PaddleOCR代码         方法一:                git clone https://gitee.com/paddlepaddle/PaddleOCR                 安装第三方库                 cd PaddleOCR                 python -m pip install -r requirments.txt         方法二:                 pip install paddleocr -i https://mirror.baidu.com/pypi/simple PS:95% 运行不成功的问题, 是在这步造成的         安装完成后 再执行 更新 默认安装的numpy版本太高。。 python -m pip install numpy==1.19.3 -i https://mirror.baidu.com/pypi/simple 四、目前PYTHON的识别比C++的高 另附上VC++的识别图 VC++版本因为太大(几个文件,无需安装,命令行取回显方式调用)和PYTHON识别库上传到BAIDU网盘中 链接: https://pan.baidu.com/s/1jC7wgx7hiQ-FsYluiIKukQ  提取码: gycx

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皓月如我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值