项目概述
本项目是一个基于深度学习和计算机视觉技术的小麦叶绿素估测系统,采用YOLOv5目标检测模型,通过图像处理技术实现对小麦叶片营养缺乏状态的智能识别与分析。系统具备图像检测、视频实时监测和摄像头实时检测等功能,为农业生产提供科学的决策支持。
技术架构
1. 核心技术栈
- 深度学习框架: PyTorch
- 目标检测模型: YOLOv5
- 图像处理: OpenCV
- 用户界面: PyQt5
- 数据处理: NumPy, Pandas
- 可视化: Matplotlib, Seaborn
2. 系统架构设计
```
小麦叶绿素估测系统
├── 用户界面层 (PyQt5)
│ ├── 登录认证模块
│ ├── 主检测界面
│ └── 结果展示模块
├── 业务逻辑层
│ ├── 图像检测逻辑
│ ├── 视频处理逻辑
│ └── 实时监测逻辑
├── 模型推理层 (YOLOv5)
│ ├── 模型加载
│ ├── 图像预处理
│ └── 结果后处理
└── 数据存储层
├── 用户信息管理
├── 检测结果存储
└── 模型权重文件
核心功能模块
1. 用户认证系统
- 主要文件: `loginUI.py`, `main_logic.py`, `utils/id_utils.py`
1.1 登录界面实现
```python
# loginUI.py - 现代化登录界面
class ModernButton(QPushButton):
def __init__(self, text, color):
super().__init__(text)
self.setFixedHeight(45)
self.setFixedWidth(200)
self.setFont(QFont("Segoe UI", 10))
self.setCursor(Qt.PointingHandCursor)
self.setStyleSheet(f'''
QPushButton { {
background-color: {color};
border: none;
border-radius: 22px;
color: white;
padding: 8px 16px;
font-weight: bold;
}}
QPushButton:hover { {
background-color: {color}dd;
transform: scale(1.05);
}}
''')
1.2 用户信息管理
```python
# utils/id_utils.py - 用户信息存储与验证
def sava_id_info(user, pwd):
"""写入账户信息到csv文件"""
headers = ['name', 'key']
values = [{'name':user, 'key':pwd}]
with open('userInfo.csv', 'a', encoding='utf-8', newline='') as fp:
writer = csv.DictWriter(fp, headers)
writer.writerows(values)
def get_id_info():
"""读取csv文件获得账户信息"""
USER_PWD = {}
with open('userInfo.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
USER_PWD[row[0]] = row[1]
return USER_PWD
2. 目标检测引擎
- 主要文件: `detect_logical.py`, `detect_logical_v2.py`
2.1 模型初始化
```python
# detect_logical.py - 模型加载与初始化
def model_init(self):
"""模型初始化函数"""
device = select_device(self.device)
self.half = device.type != 'cpu'
# Load model
self.model = attempt_load(weights, map_location=self.device)
stride = int(self.model.stride.max())
self.imgsz = check_img_size(imgsz, s=stride)
if self.half:
self.model.half() # to FP16
# Get names and colors
self.names = self.model.module.names if hasattr(self.model, 'module') else self.model.names
self.colors = [[random.randint(0, 255) for _ in range(3)] for _ in self.names]
2.2 核心检测算法
```python
# detect_logical.py - 核心检测函数
def detect(self, name_list, img):
"""图像检测核心函数"""
showimg = img
with torch.no_grad():
# 图像预处理
img = letterbox(img, new_shape=self.opt.img_size)[0]
img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB
img = np.ascontiguousarray(img)
img = torch.from_numpy(img).to(self.device)