50 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
from paddleocr import TextRecognition
import cv2
class OCRProcessor:
def __init__(self):
self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
print("OCR模型初始化完成占位")
def predict(self, image_array):
# 保持原有模型调用方式
output = self.model.predict(input=image_array)
# 结构化输出结果
results = output[0]["rec_text"]
placeholder_result = results.split(',')
return placeholder_result
# 保留原有函数接口
_processor = OCRProcessor()
def LPRNinitialize_model():
return _processor
def LPRNmodel_predict(image_array):
# 获取原始预测结果
raw_result = _processor.predict(image_array)
# 将结果合并为字符串(如果是列表的话)
if isinstance(raw_result, list):
result_str = ''.join(raw_result)
else:
result_str = str(raw_result)
# 过滤掉'·'字符
filtered_str = result_str.replace('·', '')
# 转换为字符列表
char_list = list(filtered_str)
# 确保返回长度为7的列表
if len(char_list) >= 7:
# 如果长度大于等于7取前7个字符
return char_list[:7]
else:
# 如果长度小于7用空字符串补齐到7位
return char_list + [''] * (7 - len(char_list))