news 2026/2/24 11:43:50

基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)

一、项目介绍

本文基于YOLOv12深度学习框架,设计并实现了一种高效的车辆类型识别检测系统。该系统支持12类车辆检测,包括大型巴士(big bus)、大型卡车(big truck)、不同尺寸的公交车(bus-l-, bus-s-)和小型卡车(small truck)等。项目采用自建的YOLO格式数据集,包含训练集2634张、验证集966张和测试集458张图像,通过数据增强和模型优化提升检测精度。系统整合了用户友好的UI界面,支持登录注册功能,便于用户管理和交互。实验结果表明,该系统在复杂场景下能够实现高准确率的车辆类型识别,为智能交通管理、车辆监控等应用提供了可靠的技术支持。本文详细介绍了系统设计、模型训练及实现过程,并提供了完整的Python项目源码和预训练模型。

引言
随着智能交通系统和自动驾驶技术的快速发展,车辆类型识别在交通监控、流量统计和安全管理中发挥着重要作用。传统的车辆检测方法依赖手工特征提取,难以应对复杂多变的实际场景。近年来,基于深度学习的目标检测算法(如YOLO系列)因其高速度和准确性成为研究热点。本文基于最新的YOLOv12模型,构建了一个覆盖12类车辆的检测系统,通过丰富的数据集和优化策略提升模型性能。系统结合用户友好的UI界面和登录注册模块,增强了实用性和可扩展性。项目的实现不仅验证了YOLOv12在车辆检测任务中的优势,还为相关领域的应用提供了可复现的解决方案。

目录

一、项目介绍

二、项目功能展示

2.1 用户登录系统

2.2 检测功能

2.3 检测结果显示

2.4 参数配置

2.5 其他功能

3. 技术特点

4. 系统流程

三、数据集介绍

1. 数据集类别

2. 数据集划分

数据集配置文件

四、项目环境配置

创建虚拟环境

安装所需要库

五、模型训练

训练代码

训练结果

六、核心代码

🔐登录注册验证

🎯 多重检测模式

🖼️ 沉浸式可视化

⚙️ 参数配置系统

✨ UI美学设计

🔄 智能工作流

七、项目源码(视频简介)


基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)_哔哩哔哩_bilibili

基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)

二、项目功能展示

✅ 用户登录注册:支持密码检测和安全性验证。

✅ 三种检测模式:基于YOLOv12模型,支持图片、视频和实时摄像头三种检测,精准识别目标。

✅ 双画面对比:同屏显示原始画面与检测结果。

✅ 数据可视化:实时表格展示检测目标的类别、置信度及坐标。

✅智能参数调节:提供置信度滑块,动态优化检测精度,适应不同场景需求。

✅科幻风交互界面:深色主题搭配动态光效,减少视觉疲劳,提升操作体验。

✅多线程高性能架构:独立检测线程保障流畅运行,实时状态提示,响应迅速无卡顿。

2.1 用户登录系统

  • 提供用户登录和注册功能

  • 用户名和密码验证

  • 账户信息本地存储(accounts.json)

  • 密码长度至少6位的安全要求

2.2 检测功能

  • 图片检测:支持JPG/JPEG/PNG/BMP格式图片的火焰烟雾检测

  • 视频检测:支持MP4/AVI/MOV格式视频的逐帧检测

  • 摄像头检测:实时摄像头流检测(默认摄像头0)

  • 检测结果保存到"results"目录

2.3 检测结果显示

  • 显示原始图像和检测结果图像

  • 检测结果表格展示,包含:

    • 检测到的类别

    • 置信度分数

    • 物体位置坐标(x,y)、

2.4 参数配置

  • 模型选择

  • 置信度阈值调节(0-1.0)

  • IoU(交并比)阈值调节(0-1.0)

  • 实时同步滑块和数值输入框

2.5 其他功能

  • 检测结果保存功能

  • 视频检测时自动保存结果视频

  • 状态栏显示系统状态和最后更新时间

  • 无边框窗口设计,可拖动和调整大小

3. 技术特点

  • 采用多线程处理检测任务,避免界面卡顿

  • 精美的UI设计,具有科技感的视觉效果:

    • 发光边框和按钮

    • 悬停和按下状态效果

    • 自定义滑块、表格和下拉框样式

  • 检测结果保存机制

  • 响应式布局,适应不同窗口大小

4. 系统流程

  1. 用户登录/注册

  2. 选择检测模式(图片/视频/摄像头)

  3. 调整检测参数(可选)

  4. 开始检测并查看结果

  5. 可选择保存检测结果

  6. 停止检测或切换其他模式

三、数据集介绍

本系统采用自建的车辆检测数据集,包含12 种车辆类别,涵盖不同尺寸和类型的车辆,适用于智能交通监控、自动驾驶等场景。数据集采用YOLO 格式(每张图像对应一个.txt标注文件),并划分为训练集、验证集和测试集,确保模型训练的可靠性和泛化能力。

1. 数据集类别

数据集中包含以下12 类车辆,具体类别名称及示例车辆如下:

类别名称说明示例车辆
big bus大型巴士长途客车、双层巴士
big truck大型卡车重型货运卡车
bus-l-大型公交车铰接式公交车
bus-s-小型公交车社区巴士、小型班车
car普通轿车私家车、出租车
mid truck中型卡车中型货运车辆
small bus小型巴士商务中巴、面包车
small truck小型卡车轻型货车、皮卡
truck-l-大型货车集装箱卡车
truck-m-中型货车普通货运卡车
truck-s-小型货车微型卡车、厢式货车
truck-xl-超大型货车矿用卡车、特种运输车
2. 数据集划分

数据集按照7:2:1的比例划分为训练集、验证集和测试集,具体分布如下:

数据集图像数量占比用途
训练集263470%模型训练,优化权重
验证集96620%超参数调整,防止过拟合
测试集45810%最终评估模型性能

数据集配置文件

数据集采用标准化YOLO格式组织:

train: F:\车辆种类数据集\train val: F:\车辆种类数据集\valid test: F:\车辆种类数据集\test nc: 12 names: ['big bus', 'big truck', 'bus-l-', 'bus-s-', 'car', 'mid truck', 'small bus', 'small truck', 'truck-l-', 'truck-m-', 'truck-s-', 'truck-xl-']

四、项目环境配置

创建虚拟环境

首先新建一个Anaconda环境,每个项目用不同的环境,这样项目中所用的依赖包互不干扰。

终端输入

conda create -n yolov12 python==3.9

激活虚拟环境

conda activate yolov12

安装cpu版本pytorch

pip install torch torchvision torchaudio

安装所需要库

pip install -r requirements.txt

pycharm中配置anaconda

五、模型训练

训练代码

from ultralytics import YOLO model_path = 'yolo12s.pt' data_path = 'data.yaml' if __name__ == '__main__': model = YOLO(model_path) results = model.train(data=data_path, epochs=100, batch=8, device='0', workers=0, project='runs', name='exp', )
根据实际情况更换模型 # yolov12n.yaml (nano):轻量化模型,适合嵌入式设备,速度快但精度略低。 # yolov12s.yaml (small):小模型,适合实时任务。 # yolov12m.yaml (medium):中等大小模型,兼顾速度和精度。 # yolov12b.yaml (base):基本版模型,适合大部分应用场景。 # yolov12l.yaml (large):大型模型,适合对精度要求高的任务。
  • --batch 8:每批次8张图像。
  • --epochs 100:训练100轮。
  • --datasets/data.yaml:数据集配置文件。
  • --weights yolov12s.pt:初始化模型权重,yolov12s.pt是预训练的轻量级YOLO模型。

训练结果

六、核心代码

import sys import cv2 import numpy as np from PyQt5.QtWidgets import QApplication, QMessageBox, QFileDialog from PyQt5.QtCore import QThread, pyqtSignal from ultralytics import YOLO from UiMain import UiMainWindow import time import os from PyQt5.QtWidgets import QDialog from LoginWindow import LoginWindow class DetectionThread(QThread): frame_received = pyqtSignal(np.ndarray, np.ndarray, list) # 原始帧, 检测帧, 检测结果 finished_signal = pyqtSignal() # 线程完成信号 def __init__(self, model, source, conf, iou, parent=None): super().__init__(parent) self.model = model self.source = source self.conf = conf self.iou = iou self.running = True def run(self): try: if isinstance(self.source, int) or self.source.endswith(('.mp4', '.avi', '.mov')): # 视频或摄像头 cap = cv2.VideoCapture(self.source) while self.running and cap.isOpened(): ret, frame = cap.read() if not ret: break # 保存原始帧 original_frame = frame.copy() # 检测 results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) # 发送信号 self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) # 控制帧率 time.sleep(0.03) # 约30fps cap.release() else: # 图片 frame = cv2.imread(self.source) if frame is not None: original_frame = frame.copy() results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) except Exception as e: print(f"Detection error: {e}") finally: self.finished_signal.emit() def stop(self): self.running = False class MainWindow(UiMainWindow): def __init__(self): super().__init__() # 初始化模型 self.model = None self.detection_thread = None self.current_image = None self.current_result = None self.video_writer = None self.is_camera_running = False self.is_video_running = False self.last_detection_result = None # 新增:保存最后一次检测结果 # 连接按钮信号 self.image_btn.clicked.connect(self.detect_image) self.video_btn.clicked.connect(self.detect_video) self.camera_btn.clicked.connect(self.detect_camera) self.stop_btn.clicked.connect(self.stop_detection) self.save_btn.clicked.connect(self.save_result) # 初始化模型 self.load_model() def load_model(self): try: model_name = self.model_combo.currentText() self.model = YOLO(f"{model_name}.pt") # 自动下载或加载本地模型 self.update_status(f"模型 {model_name} 加载成功") except Exception as e: QMessageBox.critical(self, "错误", f"模型加载失败: {str(e)}") self.update_status("模型加载失败") def detect_image(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择图片", "", "图片文件 (*.jpg *.jpeg *.png *.bmp)") if file_path: self.clear_results() self.current_image = cv2.imread(file_path) self.current_image = cv2.cvtColor(self.current_image, cv2.COLOR_BGR2RGB) self.display_image(self.original_image_label, self.current_image) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测图片: {os.path.basename(file_path)}") def detect_video(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择视频", "", "视频文件 (*.mp4 *.avi *.mov)") if file_path: self.clear_results() self.is_video_running = True # 初始化视频写入器 cap = cv2.VideoCapture(file_path) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = cap.get(cv2.CAP_PROP_FPS) cap.release() # 创建保存路径 save_dir = "results" os.makedirs(save_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") save_path = os.path.join(save_dir, f"result_{timestamp}.mp4") fourcc = cv2.VideoWriter_fourcc(*'mp4v') self.video_writer = cv2.VideoWriter(save_path, fourcc, fps, (frame_width, frame_height)) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测视频: {os.path.basename(file_path)}") def detect_camera(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return self.clear_results() self.is_camera_running = True # 创建检测线程 (默认使用摄像头0) conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, 0, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status("正在从摄像头检测...")

🔐登录注册验证

对应文件:LoginWindow.py

# 账户验证核心逻辑 def handle_login(self): username = self.username_input.text().strip() password = self.password_input.text().strip() if not username or not password: QMessageBox.warning(self, "警告", "用户名和密码不能为空!") return if username in self.accounts and self.accounts[username] == password: self.accept() # 验证通过 else: QMessageBox.warning(self, "错误", "用户名或密码错误!") # 密码强度检查(注册时) def handle_register(self): if len(password) < 6: # 密码长度≥6位 QMessageBox.warning(self, "警告", "密码长度至少为6位!")

🎯多重检测模式

对应文件:main.py

图片检测

def detect_image(self): file_path, _ = QFileDialog.getOpenFileName( self, "选择图片", "", "图片文件 (*.jpg *.jpeg *.png *.bmp)") if file_path: self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.start() # 启动检测线程

视频检测

def detect_video(self): file_path, _ = QFileDialog.getOpenFileName( self, "选择视频", "", "视频文件 (*.mp4 *.avi *.mov)") if file_path: self.video_writer = cv2.VideoWriter() # 初始化视频写入器 self.detection_thread = DetectionThread(self.model, file_path, conf, iou)

实时摄像头

def detect_camera(self): self.detection_thread = DetectionThread(self.model, 0, conf, iou) # 摄像头设备号0 self.detection_thread.start()

🖼️沉浸式可视化

对应文件:UiMain.py

双画面显示

def display_image(self, label, image): q_img = QImage(image.data, w, h, bytes_per_line, QImage.Format_RGB888) pixmap = QPixmap.fromImage(q_img) label.setPixmap(pixmap.scaled(label.size(), Qt.KeepAspectRatio)) # 自适应缩放

结果表格

def add_detection_result(self, class_name, confidence, x, y): self.results_table.insertRow(row) items = [ QTableWidgetItem(class_name), # 类别列 QTableWidgetItem(f"{confidence:.2f}"), # 置信度 QTableWidgetItem(f"{x:.1f}"), # X坐标 QTableWidgetItem(f"{y:.1f}") # Y坐标 ]

⚙️参数配置系统

对应文件:UiMain.py

双阈值联动控制

# 置信度阈值同步 def update_confidence(self, value): confidence = value / 100.0 self.confidence_spinbox.setValue(confidence) # 滑块→数值框 self.confidence_label.setText(f"置信度阈值: {confidence:.2f}") # IoU阈值同步 def update_iou(self, value): iou = value / 100.0 self.iou_spinbox.setValue(iou)

UI美学设计

对应文件:UiMain.py

科幻风格按钮

def create_button(self, text, color): return f""" QPushButton {{ border: 1px solid {color}; color: {color}; border-radius: 6px; }} QPushButton:hover {{ background-color: {self.lighten_color(color, 10)}; box-shadow: 0 0 10px {color}; # 悬停发光效果 }} """

动态状态栏

def update_status(self, message): self.status_bar.showMessage( f"状态: {message} | 最后更新: {time.strftime('%H:%M:%S')}" # 实时时间戳 )

🔄智能工作流

对应文件:main.py

线程管理

class DetectionThread(QThread): frame_received = pyqtSignal(np.ndarray, np.ndarray, list) # 信号量通信 def run(self): while self.running: # 多线程检测循环 results = self.model(frame, conf=self.conf, iou=self.iou) self.frame_received.emit(original_frame, result_frame, detections)

七、项目源码(视频简介)

演示与介绍视频:

基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)_哔哩哔哩_bilibili

基于深度学习YOLOv12的车辆类型识别检测系统(YOLOv12+YOLO数据集+UI界面+登录注册界面+Python项目源码+模型)

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/17 6:48:52

DC-DC电源模块技术发展概述与高性能设计趋势

DC-DC电源模块作为电子系统中的关键部件&#xff0c;负责将输入电压转换为稳定、可靠的输出电压&#xff0c;为各类负载提供精确的电力支持。其性能直接影响到整个系统的稳定性、效率与可靠性。随着电子设备向小型化、高效率、高可靠性方向发展&#xff0c;DC-DC模块的技术也在…

作者头像 李华
网站建设 2026/2/17 22:41:23

Redis 为什么这么快?——「极速快递站」的故事

咱们先从一个真实场景切入&#xff1a;电商大促时&#xff0c;每秒几万用户查商品库存&#xff0c;MySQL&#xff08;传统数据库&#xff09;查一次要几百毫秒&#xff0c;甚至卡崩&#xff1b;但Redis查一次只要几微秒&#xff0c;扛住百万请求都不慌。 为啥差距这么大&#x…

作者头像 李华
网站建设 2026/2/23 1:04:11

2026高职大数据专业毕业生:这5类数据岗位正缺人!

随着数字化转型加速&#xff0c;大数据行业人才需求持续增长。2026年高职大数据专业毕业生可重点关注以下5类紧缺岗位&#xff0c;结合CDA数据分析师证书提升竞争力。岗位1&#xff1a;数据分析师核心职责&#xff1a;通过数据挖掘与可视化辅助业务决策&#xff0c;需掌握SQL、…

作者头像 李华
网站建设 2026/2/21 17:59:22

用数据说话 AI论文软件 千笔AI VS 学术猹 专科生写作神器

随着人工智能技术的迅猛发展&#xff0c;AI辅助写作工具正逐步渗透到高校学术写作场景中&#xff0c;成为专科生、本科生、研究生完成毕业论文不可或缺的助手。越来越多的学生开始借助AI工具来提升写作效率、降低写作难度。然而&#xff0c;面对市场上琳琅满目的AI写作工具&…

作者头像 李华
网站建设 2026/2/18 20:32:08

基于Spring AI的分布式在线考试系统-事件处理架构(续)

一、分布式在线考试系统完整架构图&#xff08;细化版&#xff09; 以下是包含服务分层、中间件、数据流向、事件通信的完整架构图&#xff0c;直观展示各组件的交互关系&#xff1a; #mermaid-svg-Kf5ryIQKoY8I7WLm{font-family:"trebuchet ms",verdana,arial,sans-…

作者头像 李华