更新接口

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

22
main.py
View File

@@ -361,8 +361,8 @@ class MainWindow(QMainWindow):
# 矫正车牌图像
corrected_image = self.correct_license_plate(detection)
# 获取车牌号(占位)
plate_number = self.recognize_plate_number(corrected_image)
# 获取车牌号,传入车牌类型信息
plate_number = self.recognize_plate_number(corrected_image, detection['class_name'])
# 创建车牌显示组件
plate_widget = LicensePlateWidget(
@@ -389,7 +389,7 @@ class MainWindow(QMainWindow):
detection['keypoints']
)
def recognize_plate_number(self, corrected_image):
def recognize_plate_number(self, corrected_image, class_name):
"""识别车牌号"""
if corrected_image is None:
return "识别失败"
@@ -399,9 +399,21 @@ class MainWindow(QMainWindow):
# 函数名改成一样的了,所以不要修改这里了,想用哪个模块直接导入
result = LPRNmodel_predict(corrected_image)
# 将字符列表转换为字符串
# 将字符列表转换为字符串支持8位车牌号
if isinstance(result, list) and len(result) >= 7:
return ''.join(result[:7])
# 根据车牌类型决定显示位数
if class_name == '绿牌' and len(result) >= 8:
# 绿牌显示8位过滤掉空字符占位符
plate_chars = [char for char in result[:8] if char != '']
# 如果过滤后确实有8位显示8位否则显示7位
if len(plate_chars) == 8:
return ''.join(plate_chars)
else:
return ''.join(plate_chars[:7])
else:
# 蓝牌或其他类型显示前7位过滤掉空字符
plate_chars = [char for char in result[:7] if char != '']
return ''.join(plate_chars)
else:
return "识别失败"
except Exception as e: