Merge remote-tracking branch 'origin/main-66' into main-66
This commit is contained in:
commit
74821bb02c
@ -5,6 +5,18 @@ import cv2
|
||||
class OCRProcessor:
|
||||
def __init__(self):
|
||||
self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
|
||||
# 定义允许的字符集合(不包含空白字符)
|
||||
self.allowed_chars = [
|
||||
# 中文省份简称
|
||||
'京', '沪', '津', '渝', '冀', '晋', '蒙', '辽', '吉', '黑',
|
||||
'苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤',
|
||||
'桂', '琼', '川', '贵', '云', '藏', '陕', '甘', '青', '宁', '新',
|
||||
# 字母 A-Z
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
# 数字 0-9
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
]
|
||||
print("OCR模型初始化完成(占位)")
|
||||
|
||||
def predict(self, image_array):
|
||||
@ -15,6 +27,14 @@ class OCRProcessor:
|
||||
placeholder_result = results.split(',')
|
||||
return placeholder_result
|
||||
|
||||
def filter_allowed_chars(self, text):
|
||||
"""只保留允许的字符"""
|
||||
filtered_text = ""
|
||||
for char in text:
|
||||
if char in self.allowed_chars:
|
||||
filtered_text += char
|
||||
return filtered_text
|
||||
|
||||
# 保留原有函数接口
|
||||
_processor = OCRProcessor()
|
||||
|
||||
@ -42,8 +62,12 @@ def LPRNmodel_predict(image_array):
|
||||
else:
|
||||
result_str = str(raw_result)
|
||||
|
||||
# 过滤掉'·'字符
|
||||
# 过滤掉'·'和'-'字符
|
||||
filtered_str = result_str.replace('·', '')
|
||||
filtered_str = filtered_str.replace('-', '')
|
||||
|
||||
# 只保留允许的字符
|
||||
filtered_str = _processor.filter_allowed_chars(filtered_str)
|
||||
|
||||
# 转换为字符列表
|
||||
char_list = list(filtered_str)
|
||||
|
Loading…
x
Reference in New Issue
Block a user