From afba7af80b12c6f12d1e898b841ad189ee44a842 Mon Sep 17 00:00:00 2001 From: spdis Date: Mon, 1 Sep 2025 00:01:38 +0800 Subject: [PATCH] OCR --- .idea/License_plate_recognition.iml | 2 +- .idea/misc.xml | 2 +- .idea/vcs.xml | 2 +- OCR_part/ocr_interface.py | 23 ++++++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.idea/License_plate_recognition.iml b/.idea/License_plate_recognition.iml index 57ba54e..fb56de3 100644 --- a/.idea/License_plate_recognition.iml +++ b/.idea/License_plate_recognition.iml @@ -2,7 +2,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index aeaf94a..fb9fc56 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 8306744..288b36b 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/OCR_part/ocr_interface.py b/OCR_part/ocr_interface.py index 71812d3..4f88aef 100644 --- a/OCR_part/ocr_interface.py +++ b/OCR_part/ocr_interface.py @@ -22,7 +22,28 @@ def initialize_ocr_model(): return _processor def ocr_predict(image_array): - return _processor.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))