Administrator
2023-01-16 6f324f1471a5e28188e9f4206b46cbafdf09d04c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re
import time
 
import cv2
from cnocr import CnOcr
 
 
# 图像识别类
class OcrUtil:
    __ocr = CnOcr()
 
    @classmethod
    def ocr(cls, mat):
        res = cls.__ocr.ocr(mat)
        return res
 
    # 返回(识别内容,位置信息)
    @classmethod
    def ocr_with_key(cls, mat, key):
        start = time.time()
        res = cls.ocr(mat)
        res_final = []
        for r in res:
            text = r["text"]
            if re.match(key, text):
                res_final.append((text, r["position"]))
        print("识别时间",time.time() - start)
        return res_final