Compare commits
No commits in common. "2eba46bc403f563db356172493507788cb1c86e9" and "b5839d2c3608b241797a4364b205e9443aee824b" have entirely different histories.
2eba46bc40
...
b5839d2c36
2
.idea/License_plate_recognition.iml
generated
2
.idea/License_plate_recognition.iml
generated
@ -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="cnm" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="pytorh" 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
2
.idea/misc.xml
generated
@ -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="cnm" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="pytorh" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@ -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="$PROJECT_DIR$/.." vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -207,7 +207,7 @@ class LicensePlatePreprocessor:
|
|||||||
print(f"图像预处理失败: {e}")
|
print(f"图像预处理失败: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def LPRNinitialize_model():
|
def initialize_crnn_model():
|
||||||
"""
|
"""
|
||||||
初始化CRNN模型
|
初始化CRNN模型
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ def LPRNinitialize_model():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def LPRNmodel_predict(image_array):
|
def crnn_predict(image_array):
|
||||||
"""
|
"""
|
||||||
CRNN车牌号识别接口函数
|
CRNN车牌号识别接口函数
|
||||||
|
|
||||||
|
@ -1,49 +1,36 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from paddleocr import TextRecognition
|
|
||||||
import cv2
|
|
||||||
|
|
||||||
class OCRProcessor:
|
def initialize_ocr_model():
|
||||||
def __init__(self):
|
"""
|
||||||
self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
|
初始化OCR模型
|
||||||
|
|
||||||
|
返回:
|
||||||
|
bool: 初始化是否成功
|
||||||
|
"""
|
||||||
|
# OCR模型初始化代码
|
||||||
|
# 例如: 加载预训练模型、设置参数等
|
||||||
|
|
||||||
print("OCR模型初始化完成(占位)")
|
print("OCR模型初始化完成(占位)")
|
||||||
|
return True
|
||||||
|
|
||||||
def predict(self, image_array):
|
def ocr_predict(image_array):
|
||||||
# 保持原有模型调用方式
|
"""
|
||||||
output = self.model.predict(input=image_array)
|
OCR车牌号识别接口函数
|
||||||
# 结构化输出结果
|
|
||||||
results = output[0]["rec_text"]
|
参数:
|
||||||
placeholder_result = results.split(',')
|
image_array: numpy数组格式的车牌图像,已经过矫正处理
|
||||||
|
|
||||||
|
返回:
|
||||||
|
list: 包含7个字符的列表,代表车牌号的每个字符
|
||||||
|
例如: ['京', 'A', '1', '2', '3', '4', '5']
|
||||||
|
"""
|
||||||
|
# 这是OCR部分的占位函数
|
||||||
|
# 实际实现时,这里应该包含:
|
||||||
|
# 1. 图像预处理
|
||||||
|
# 2. OCR模型推理
|
||||||
|
# 3. 后处理和字符识别
|
||||||
|
|
||||||
|
# 临时返回占位结果
|
||||||
|
placeholder_result = ['待', '识', '别', '0', '0', '0', '0']
|
||||||
return placeholder_result
|
return placeholder_result
|
||||||
|
|
||||||
# 保留原有函数接口
|
|
||||||
_processor = OCRProcessor()
|
|
||||||
|
|
||||||
def LPRNinitialize_model():
|
|
||||||
return _processor
|
|
||||||
|
|
||||||
def LPRNmodel_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))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
22
main.py
22
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 LPRNmodel_predict
|
#from OCR_part.ocr_interface import ocr_predict
|
||||||
from OCR_part.ocr_interface import LPRNinitialize_model
|
#from OCR_part.ocr_interface import initialize_ocr_model
|
||||||
# 使用CRNN进行车牌字符识别(可选)同时也要修改第395,396行
|
# 使用CRNN进行车牌字符识别
|
||||||
# from CRNN_part.crnn_interface import LPRNmodel_predict
|
from CRNN_part.crnn_interface import crnn_predict
|
||||||
# from CRNN_part.crnn_interface import LPRNinitialize_model
|
from CRNN_part.crnn_interface import initialize_crnn_model
|
||||||
|
|
||||||
class CameraThread(QThread):
|
class CameraThread(QThread):
|
||||||
"""摄像头线程类"""
|
"""摄像头线程类"""
|
||||||
@ -163,8 +163,9 @@ class MainWindow(QMainWindow):
|
|||||||
self.init_detector()
|
self.init_detector()
|
||||||
self.init_camera()
|
self.init_camera()
|
||||||
|
|
||||||
# 初始化OCR/CRNN模型(函数名改成一样的了,所以不要修改这里了,想用哪个模块直接导入)
|
# 初始化OCR/CRNN模型(具体用哪个模块识别车牌号就写在这儿)
|
||||||
LPRNinitialize_model()
|
#initialize_ocr_model()
|
||||||
|
initialize_crnn_model()
|
||||||
|
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
@ -389,9 +390,10 @@ class MainWindow(QMainWindow):
|
|||||||
return "识别失败"
|
return "识别失败"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 预测函数(来自模块)
|
# 使用OCR接口进行识别
|
||||||
# 函数名改成一样的了,所以不要修改这里了,想用哪个模块直接导入
|
# 可以根据需要切换为CRNN: crnn_predict(corrected_image)
|
||||||
result = LPRNmodel_predict(corrected_image)
|
#result = ocr_predict(corrected_image)
|
||||||
|
result = crnn_predict(corrected_image)
|
||||||
|
|
||||||
# 将字符列表转换为字符串
|
# 将字符列表转换为字符串
|
||||||
if isinstance(result, list) and len(result) >= 7:
|
if isinstance(result, list) and len(result) >= 7:
|
||||||
|
@ -11,11 +11,6 @@ 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user