更新接口

This commit is contained in:
Viajero 2025-09-16 11:15:06 +08:00
parent 233ef20ce2
commit 8ace9df86a

View File

@ -5,6 +5,18 @@ import cv2
class OCRProcessor: class OCRProcessor:
def __init__(self): def __init__(self):
self.model = TextRecognition(model_name="PP-OCRv5_server_rec") 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模型初始化完成占位") print("OCR模型初始化完成占位")
def predict(self, image_array): def predict(self, image_array):
@ -15,6 +27,14 @@ class OCRProcessor:
placeholder_result = results.split(',') placeholder_result = results.split(',')
return placeholder_result 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() _processor = OCRProcessor()
@ -42,8 +62,12 @@ def LPRNmodel_predict(image_array):
else: else:
result_str = str(raw_result) result_str = str(raw_result)
# 过滤掉'·'字符 # 过滤掉'·'和'-'字符
filtered_str = result_str.replace('·', '') filtered_str = result_str.replace('·', '')
filtered_str = filtered_str.replace('-', '')
# 只保留允许的字符
filtered_str = _processor.filter_allowed_chars(filtered_str)
# 转换为字符列表 # 转换为字符列表
char_list = list(filtered_str) char_list = list(filtered_str)