Compare commits
3 Commits
hi3861
...
2a77e6ca8a
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a77e6ca8a | |||
| 56e7347c01 | |||
| 1c8e15bcd8 |
BIN
LPRNET_part/LPRNet__iteration_74000.pth
Normal file
BIN
LPRNET_part/LPRNet__iteration_74000.pth
Normal file
Binary file not shown.
BIN
LPRNET_part/吉CF18040.jpg
Normal file
BIN
LPRNET_part/吉CF18040.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
LPRNET_part/藏A0DBN8.jpg
Normal file
BIN
LPRNET_part/藏A0DBN8.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
45
main.py
45
main.py
@@ -3,7 +3,7 @@ import cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||||
QLabel, QPushButton, QScrollArea, QFrame, QSizePolicy
|
QLabel, QPushButton, QScrollArea, QFrame, QSizePolicy,QFileDialog
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import QTimer, Qt, pyqtSignal, QThread
|
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
|
||||||
@@ -206,7 +206,12 @@ class MainWindow(QMainWindow):
|
|||||||
self.start_button.clicked.connect(self.start_camera)
|
self.start_button.clicked.connect(self.start_camera)
|
||||||
self.stop_button.clicked.connect(self.stop_camera)
|
self.stop_button.clicked.connect(self.stop_camera)
|
||||||
self.stop_button.setEnabled(False)
|
self.stop_button.setEnabled(False)
|
||||||
|
self.btn_image = QPushButton('选择图片')
|
||||||
|
self.btn_video = QPushButton('选择视频')
|
||||||
|
self.btn_image.clicked.connect(self.open_image_file)
|
||||||
|
self.btn_video.clicked.connect(self.open_video_file)
|
||||||
|
button_layout.addWidget(self.btn_image)
|
||||||
|
button_layout.addWidget(self.btn_video)
|
||||||
button_layout.addWidget(self.start_button)
|
button_layout.addWidget(self.start_button)
|
||||||
button_layout.addWidget(self.stop_button)
|
button_layout.addWidget(self.stop_button)
|
||||||
button_layout.addStretch()
|
button_layout.addStretch()
|
||||||
@@ -426,6 +431,42 @@ class MainWindow(QMainWindow):
|
|||||||
self.camera_thread.stop_camera()
|
self.camera_thread.stop_camera()
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
|
def open_image_file(self):
|
||||||
|
file_path, _ = QFileDialog.getOpenFileName(self, '选择图片', '', '图片文件 (*.jpg *.png)')
|
||||||
|
if file_path:
|
||||||
|
image = cv2.imread(file_path)
|
||||||
|
self.process_image(image)
|
||||||
|
|
||||||
|
def open_video_file(self):
|
||||||
|
file_path, _ = QFileDialog.getOpenFileName(self, '选择视频', '', '视频文件 (*.mp4 *.avi)')
|
||||||
|
if file_path:
|
||||||
|
self.cap = cv2.VideoCapture(file_path)
|
||||||
|
self.video_timer = QTimer()
|
||||||
|
self.video_timer.timeout.connect(self.process_video_frame)
|
||||||
|
self.video_timer.start(30)
|
||||||
|
|
||||||
|
def process_image(self, image):
|
||||||
|
self.detections = self.detector.detect_license_plates(image)
|
||||||
|
display_image = self.draw_detections(image.copy())
|
||||||
|
self.display_static_image(display_image)
|
||||||
|
self.update_results_display()
|
||||||
|
|
||||||
|
def process_video_frame(self):
|
||||||
|
ret, frame = self.cap.read()
|
||||||
|
if ret:
|
||||||
|
self.process_image(frame)
|
||||||
|
else:
|
||||||
|
self.video_timer.stop()
|
||||||
|
self.cap.release()
|
||||||
|
|
||||||
|
def display_static_image(self, image):
|
||||||
|
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
|
h, w, ch = rgb_image.shape
|
||||||
|
bytes_per_line = ch * w
|
||||||
|
qt_image = QImage(rgb_image.data, w, h, bytes_per_line, QImage.Format_RGB888)
|
||||||
|
pixmap = QPixmap.fromImage(qt_image)
|
||||||
|
self.camera_label.setPixmap(pixmap.scaled(self.camera_label.size(), Qt.KeepAspectRatio))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
|
|||||||
99
test_lpr_real_images.py
Normal file
99
test_lpr_real_images.py
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
LPRNet接口真实图片测试脚本
|
||||||
|
测试LPRNET_part目录下的真实车牌图片
|
||||||
|
"""
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
import os
|
||||||
|
from LPRNET_part.lpr_interface import LPRNinitialize_model, LPRNmodel_predict
|
||||||
|
|
||||||
|
def test_real_images():
|
||||||
|
"""
|
||||||
|
测试LPRNET_part目录下的真实车牌图片
|
||||||
|
"""
|
||||||
|
print("=== LPRNet真实图片测试 ===")
|
||||||
|
|
||||||
|
# 初始化模型
|
||||||
|
print("1. 初始化LPRNet模型...")
|
||||||
|
success = LPRNinitialize_model()
|
||||||
|
if not success:
|
||||||
|
print("模型初始化失败!")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 获取LPRNET_part目录下的图片文件
|
||||||
|
lprnet_dir = "LPRNET_part"
|
||||||
|
image_files = []
|
||||||
|
|
||||||
|
if os.path.exists(lprnet_dir):
|
||||||
|
for file in os.listdir(lprnet_dir):
|
||||||
|
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp')):
|
||||||
|
image_files.append(os.path.join(lprnet_dir, file))
|
||||||
|
|
||||||
|
if not image_files:
|
||||||
|
print("未找到图片文件!")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"2. 找到 {len(image_files)} 个图片文件")
|
||||||
|
|
||||||
|
# 测试每个图片
|
||||||
|
for i, image_path in enumerate(image_files, 1):
|
||||||
|
print(f"\n--- 测试图片 {i}: {os.path.basename(image_path)} ---")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 使用支持中文路径的方式读取图片
|
||||||
|
image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_COLOR)
|
||||||
|
|
||||||
|
if image is None:
|
||||||
|
print(f"无法读取图片: {image_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"图片尺寸: {image.shape}")
|
||||||
|
|
||||||
|
# 进行预测
|
||||||
|
result = LPRNmodel_predict(image)
|
||||||
|
print(f"识别结果: {result}")
|
||||||
|
print(f"识别车牌号: {''.join(result)}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"处理图片 {image_path} 时出错: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
print("\n=== 测试完成 ===")
|
||||||
|
|
||||||
|
def test_image_loading():
|
||||||
|
"""
|
||||||
|
测试图片加载方式
|
||||||
|
"""
|
||||||
|
print("\n=== 图片加载测试 ===")
|
||||||
|
|
||||||
|
lprnet_dir = "LPRNET_part"
|
||||||
|
|
||||||
|
if os.path.exists(lprnet_dir):
|
||||||
|
for file in os.listdir(lprnet_dir):
|
||||||
|
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp')):
|
||||||
|
image_path = os.path.join(lprnet_dir, file)
|
||||||
|
print(f"\n测试文件: {file}")
|
||||||
|
|
||||||
|
# 方法1: 普通cv2.imread
|
||||||
|
img1 = cv2.imread(image_path)
|
||||||
|
print(f"cv2.imread结果: {img1 is not None}")
|
||||||
|
|
||||||
|
# 方法2: 支持中文路径的方式
|
||||||
|
try:
|
||||||
|
img2 = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_COLOR)
|
||||||
|
print(f"cv2.imdecode结果: {img2 is not None}")
|
||||||
|
if img2 is not None:
|
||||||
|
print(f"图片尺寸: {img2.shape}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"cv2.imdecode失败: {e}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 首先测试图片加载
|
||||||
|
test_image_loading()
|
||||||
|
|
||||||
|
# 然后测试完整的识别流程
|
||||||
|
test_real_images()
|
||||||
Reference in New Issue
Block a user