更新接口

This commit is contained in:
2025-09-04 00:07:52 +08:00
parent 95aa6b6bba
commit 6c7f013a0c
5 changed files with 290 additions and 187 deletions

View File

@@ -282,14 +282,15 @@ def LPRNmodel_predict(image_array):
image_array: numpy数组格式的车牌图像已经过矫正处理
返回:
list: 包含7个字符的列表,代表车牌号的每个字符
例如: ['', 'A', '1', '2', '3', '4', '5']
list: 包含最多8个字符的列表,代表车牌号的每个字符
例如: ['', 'A', '1', '2', '3', '4', '5', ''] (蓝牌7位+占位符)
['', 'A', 'D', '1', '2', '3', '4', '5'] (绿牌8位)
"""
global crnn_model, crnn_decoder, crnn_preprocessor, device
if crnn_model is None or crnn_decoder is None or crnn_preprocessor is None:
print("CRNN模型未初始化请先调用initialize_crnn_model()")
return ['', '', '', '0', '0', '0', '0']
return ['', '', '', '0', '0', '0', '0', '0']
try:
# 预处理图像
@@ -314,13 +315,17 @@ def LPRNmodel_predict(image_array):
# 将字符串转换为字符列表
char_list = list(predicted_text)
# 确保返回7个字符(车牌标准长度)
# 确保返回至少7个字符最多8个字符
if len(char_list) < 7:
# 如果识别结果少于7个字符用'0'补齐
# 如果识别结果少于7个字符用'0'补齐到7位
char_list.extend(['0'] * (7 - len(char_list)))
elif len(char_list) > 7:
# 如果识别结果多于7个字符,截取前7
char_list = char_list[:7]
elif len(char_list) > 8:
# 如果识别结果多于8个字符,截取前8
char_list = char_list[:8]
# 如果是7位补齐到8位以保持接口一致性第8位用空字符或占位符
if len(char_list) == 7:
char_list.append('') # 添加空字符作为第8位占位符
return char_list
@@ -328,4 +333,4 @@ def LPRNmodel_predict(image_array):
print(f"CRNN识别失败: {e}")
import traceback
traceback.print_exc()
return ['', '', '', '', '0', '0', '0']
return ['', '', '', '', '0', '0', '0', '0']