ocr-v1 #4
@ -2,16 +2,25 @@ import numpy as np
|
||||
from paddleocr import TextRecognition
|
||||
import cv2
|
||||
|
||||
class OCRProcessor:
|
||||
def __init__(self):
|
||||
self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
|
||||
print("OCR模型初始化完成(占位)")
|
||||
|
||||
def predict(self, image_array):
|
||||
# 保持原有模型调用方式
|
||||
output = self.model.predict(input=image_array)
|
||||
# 结构化输出结果
|
||||
results = output[0]["rec_text"]
|
||||
placeholder_result = results.split(',')
|
||||
return placeholder_result
|
||||
|
||||
# 保留原有函数接口
|
||||
_processor = OCRProcessor()
|
||||
|
||||
def initialize_ocr_model():
|
||||
model = TextRecognition(model_name="PP-OCRv5_server_rec")
|
||||
print("OCR模型初始化完成(占位)")
|
||||
return model
|
||||
return _processor
|
||||
|
||||
def ocr_predict(image_array):
|
||||
# 保持原有模型调用方式
|
||||
output = initialize_ocr_model().predict(input=image_array)
|
||||
# 结构化输出结果
|
||||
results = output[0]["rec_text"]
|
||||
placeholder_result = results.split(',')
|
||||
return placeholder_result
|
||||
return _processor.predict(image_array)
|
||||
|
||||
|
14
main.py
14
main.py
@ -9,10 +9,10 @@ from PyQt5.QtCore import QTimer, Qt, pyqtSignal, QThread
|
||||
from PyQt5.QtGui import QImage, QPixmap, QFont, QPainter, QPen, QColor
|
||||
import os
|
||||
from yolopart.detector import LicensePlateYOLO
|
||||
#from OCR_part.ocr_interface import ocr_predict
|
||||
#from OCR_part.ocr_interface import initialize_ocr_model
|
||||
from OCR_part.ocr_interface import ocr_predict
|
||||
from OCR_part.ocr_interface import initialize_ocr_model
|
||||
# 使用CRNN进行车牌字符识别
|
||||
from CRNN_part.crnn_interface import crnn_predict
|
||||
# from CRNN_part.crnn_interface import crnn_predict
|
||||
from CRNN_part.crnn_interface import initialize_crnn_model
|
||||
|
||||
class CameraThread(QThread):
|
||||
@ -164,8 +164,8 @@ class MainWindow(QMainWindow):
|
||||
self.init_camera()
|
||||
|
||||
# 初始化OCR/CRNN模型(具体用哪个模块识别车牌号就写在这儿)
|
||||
#initialize_ocr_model()
|
||||
initialize_crnn_model()
|
||||
initialize_ocr_model()
|
||||
# initialize_crnn_model()
|
||||
|
||||
|
||||
def init_ui(self):
|
||||
@ -392,8 +392,8 @@ class MainWindow(QMainWindow):
|
||||
try:
|
||||
# 使用OCR接口进行识别
|
||||
# 可以根据需要切换为CRNN: crnn_predict(corrected_image)
|
||||
#result = ocr_predict(corrected_image)
|
||||
result = crnn_predict(corrected_image)
|
||||
result = ocr_predict(corrected_image)
|
||||
# result = crnn_predict(corrected_image)
|
||||
|
||||
# 将字符列表转换为字符串
|
||||
if isinstance(result, list) and len(result) >= 7:
|
||||
|
Loading…
x
Reference in New Issue
Block a user