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中文識別》
總結
以上是生活随笔為你收集整理的PaddleOCR加载chinese_ocr_db_crnn_server/chinese_ocr_db_crnn_modile模型进行中英文混合预测(代码)实践的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 金士顿u盘无法格式化怎么办 求助:金士顿
- 下一篇: PaddleOCR加载chinese_o