Compare commits

..

9 Commits

7 changed files with 65 additions and 49 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="pytorh" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="cnm" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="PyDocumentationSettings"> <component name="PyDocumentationSettings">

2
.idea/misc.xml generated
View File

@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="pytorh" /> <option name="sdkName" value="pytorh" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="pytorh" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="cnm" project-jdk-type="Python SDK" />
</project> </project>

2
.idea/vcs.xml generated
View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -207,7 +207,7 @@ class LicensePlatePreprocessor:
print(f"图像预处理失败: {e}") print(f"图像预处理失败: {e}")
return None return None
def initialize_crnn_model(): def LPRNinitialize_model():
""" """
初始化CRNN模型 初始化CRNN模型
@ -274,7 +274,7 @@ def initialize_crnn_model():
traceback.print_exc() traceback.print_exc()
return False return False
def crnn_predict(image_array): def LPRNmodel_predict(image_array):
""" """
CRNN车牌号识别接口函数 CRNN车牌号识别接口函数

View File

@ -1,36 +1,49 @@
import numpy as np import numpy as np
from paddleocr import TextRecognition
import cv2
def initialize_ocr_model(): class OCRProcessor:
""" def __init__(self):
初始化OCR模型 self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
print("OCR模型初始化完成占位")
返回: def predict(self, image_array):
bool: 初始化是否成功 # 保持原有模型调用方式
""" output = self.model.predict(input=image_array)
# OCR模型初始化代码 # 结构化输出结果
# 例如: 加载预训练模型、设置参数等 results = output[0]["rec_text"]
placeholder_result = results.split(',')
return placeholder_result
print("OCR模型初始化完成占位") # 保留原有函数接口
return True _processor = OCRProcessor()
def ocr_predict(image_array): def LPRNinitialize_model():
""" return _processor
OCR车牌号识别接口函数
参数: def LPRNmodel_predict(image_array):
image_array: numpy数组格式的车牌图像已经过矫正处理 # 获取原始预测结果
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))
返回:
list: 包含7个字符的列表代表车牌号的每个字符
例如: ['', 'A', '1', '2', '3', '4', '5']
"""
# 这是OCR部分的占位函数
# 实际实现时,这里应该包含:
# 1. 图像预处理
# 2. OCR模型推理
# 3. 后处理和字符识别
# 临时返回占位结果
placeholder_result = ['', '', '', '0', '0', '0', '0']
return placeholder_result

22
main.py
View File

@ -9,11 +9,11 @@ from PyQt5.QtCore import QTimer, Qt, pyqtSignal, QThread
from PyQt5.QtGui import QImage, QPixmap, QFont, QPainter, QPen, QColor from PyQt5.QtGui import QImage, QPixmap, QFont, QPainter, QPen, QColor
import os import os
from yolopart.detector import LicensePlateYOLO from yolopart.detector import LicensePlateYOLO
#from OCR_part.ocr_interface import ocr_predict from OCR_part.ocr_interface import LPRNmodel_predict
#from OCR_part.ocr_interface import initialize_ocr_model from OCR_part.ocr_interface import LPRNinitialize_model
# 使用CRNN进行车牌字符识别 # 使用CRNN进行车牌字符识别可选同时也要修改第395396行
from CRNN_part.crnn_interface import crnn_predict # from CRNN_part.crnn_interface import LPRNmodel_predict
from CRNN_part.crnn_interface import initialize_crnn_model # from CRNN_part.crnn_interface import LPRNinitialize_model
class CameraThread(QThread): class CameraThread(QThread):
"""摄像头线程类""" """摄像头线程类"""
@ -163,9 +163,8 @@ class MainWindow(QMainWindow):
self.init_detector() self.init_detector()
self.init_camera() self.init_camera()
# 初始化OCR/CRNN模型具体用哪个模块识别车牌号就写在这儿 # 初始化OCR/CRNN模型函数名改成一样的了所以不要修改这里了想用哪个模块直接导入
#initialize_ocr_model() LPRNinitialize_model()
initialize_crnn_model()
def init_ui(self): def init_ui(self):
@ -390,10 +389,9 @@ class MainWindow(QMainWindow):
return "识别失败" return "识别失败"
try: try:
# 使用OCR接口进行识别 # 预测函数(来自模块)
# 可以根据需要切换为CRNN: crnn_predict(corrected_image) # 函数名改成一样的了,所以不要修改这里了,想用哪个模块直接导入
#result = ocr_predict(corrected_image) result = LPRNmodel_predict(corrected_image)
result = crnn_predict(corrected_image)
# 将字符列表转换为字符串 # 将字符列表转换为字符串
if isinstance(result, list) and len(result) >= 7: if isinstance(result, list) and len(result) >= 7:

View File

@ -11,6 +11,11 @@ PyQt5>=5.15.0
# 图像处理 # 图像处理
Pillow>=8.0.0 Pillow>=8.0.0
#paddleocr
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
python -m pip install "paddleocr[all]"
# 可选如果需要GPU加速 # 可选如果需要GPU加速
# torch>=1.9.0 # torch>=1.9.0
# torchvision>=0.10.0 # torchvision>=0.10.0