From 3cfa1332c0807a74b4ac5a2150500841f5299147 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 08 三月 2023 22:54:09 +0800 Subject: [PATCH] 首板加入,安全笔数与H撤笔数优化 --- ocr/ocr_util.py | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/ocr/ocr_util.py b/ocr/ocr_util.py index 408e6ef..3658e9f 100644 --- a/ocr/ocr_util.py +++ b/ocr/ocr_util.py @@ -2,12 +2,14 @@ import time import cv2 +import easyocr from cnocr import CnOcr # 鍥惧儚璇嗗埆绫� class OcrUtil: __ocr = CnOcr() + reader = easyocr.Reader(['en'], gpu=False) @classmethod def ocr(cls, mat): @@ -28,3 +30,23 @@ (int(ps[2][0]), int(ps[2][1])), (int(ps[3][0]), int(ps[3][1]))])) print("璇嗗埆鏃堕棿", time.time() - start) return res_final + + @classmethod + def ocr_num(cls, mat, key): + start = time.time() + res = cls.reader.readtext(mat, detail=1, text_threshold=0.6, mag_ratio=1.5) + res_final = [] + if res: + for r in res: + text = r[1] + if re.match(key, text): + ps = r[0] + res_final.append((text, [(int(ps[0][0]), int(ps[0][1])), (int(ps[1][0]), int(ps[1][1])), + (int(ps[2][0]), int(ps[2][1])), (int(ps[3][0]), int(ps[3][1]))])) + print("鏁板瓧璇嗗埆鏃堕棿", time.time() - start) + return res_final + + +if __name__ == "__main__": + result = OcrUtil.ocr_num("D:/test1.png", "000977") + print(result) -- Gitblit v1.8.0