修改了模块的函数名,现在想用哪个模块直接导入即可
This commit is contained in:
		@@ -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车牌号识别接口函数
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,10 +18,10 @@ class OCRProcessor:
 | 
				
			|||||||
# 保留原有函数接口
 | 
					# 保留原有函数接口
 | 
				
			||||||
_processor = OCRProcessor()
 | 
					_processor = OCRProcessor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def initialize_ocr_model():
 | 
					def LPRNinitialize_model():
 | 
				
			||||||
    return _processor
 | 
					    return _processor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def ocr_predict(image_array):
 | 
					def LPRNmodel_predict(image_array):
 | 
				
			||||||
    # 获取原始预测结果
 | 
					    # 获取原始预测结果
 | 
				
			||||||
    raw_result = _processor.predict(image_array)
 | 
					    raw_result = _processor.predict(image_array)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.py
									
									
									
									
									
								
							@@ -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进行车牌字符识别(可选)同时也要修改第395,396行
 | 
					# 使用CRNN进行车牌字符识别(可选)同时也要修改第395,396行
 | 
				
			||||||
# 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:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user