烟草叶病虫害检测系统
YOLO+DeepSeek+Pytorch+SpringBoot+Flask+Vue
共4种病虫害,[“白星病”,“花叶病”,“烟青虫”,“叶厚病”]
结合DeepSeek、Qwen等大模型,给出相关建议。设置智能问的小助手,调用ai大模型进行实时对话与分析。
支持分用户管理,管理员可查看所有记录,普通用户只能看自己。
界面简洁美观,支持主题色修改、布局样式修改、组件大小修改等。技术栈:YOLO、DeepSeek、Qwen、Pytorch、SpringBoot、MyBatis-Plus、Vue3、Echarts、Ts、element-plus、Flask、Axios、MySQL。
系统还支持分用户管理,分为管理员和普通用户。普通用户只能查看自己的记录。

附:
1.整理好的yolo格式的数据集
2.详细的系统部署教程
3.实时视频,摄像头,图片检测
4.代码简洁,有注释
5.提供训练好的yolo权重
基于 YOLO + DeepSeek 的烟草叶病虫害检测系统 的完整构建代码与架构说明,支持 4 类病虫害检测(白星病、花叶病、烟青虫、叶厚病),结合大模型提供 AI 建议,具备用户权限管理、可视化界面和多模态检测功能。
✅ 项目技术栈:
后端:Flask / SpringBoot + MyBatis-Plus + MySQL
前端:Vue3 + TypeScript + Element Plus + ECharts
AI 模型:YOLOv8 + DeepSeek / Qwen 大模型
部署:Docker 可选
TobaccoDiseaseDetection/
├── backend/ # 后端(Flask 或 SpringBoot)
│ ├── app.py # Flask 主程序
│ ├── models/
│ │ └── best.pt # 训练好的 YOLO 权重
│ ├── uploads/ # 上传图片
│ ├── outputs/ # 检测结果图
│ ├── reports/ # PDF 报告
│ └── database.sql # MySQL 表结构
├── frontend/ # Vue3 前端
│ ├── src/
│ │ ├── views/
│ │ │ ├── login.vue
│ │ │ ├── dashboard.vue
│ │ │ ├── detect.vue
│ │ │ └── aiQ&A.vue
│ │ └── utils/api.js # Axios 请求封装
│ └── public/index.html
├── datasets/ # YOLO 格式数据集(含标注)
│ ├── images/
│ │ ├── train/
│ │ └── val/
│ └── labels/
└── requirements.txt # 依赖
# backend/app.py
from flask import Flask, request, jsonify, send_file
from ultralytics import YOLO
import cv2
import base64
import json
import requests
from datetime import datetime
import os
app = Flask(__name__)
# 加载 YOLO 模型
model = YOLO('models/best.pt')# 4类:['white_spot', 'mosaic_virus', 'tobacco_bug', 'leaf_thick']
# 中文类别映射
class_map ={
'white_spot':'白星病',
'mosaic_virus':'花叶病',
'tobacco_bug':'烟青虫',
'leaf_thick':'叶厚病'
}
# DeepSeek API 调用(模拟)
defget_ai_advice(detections):
prompt =f"这是烟草叶片的病虫害检测结果:{detections}。请给出专业防治建议,包括原因、预防措施、化学药剂推荐、生物防治方法等,用中文回答。"
try:
response = requests.post(
"https://api.deepseek.com/v1/chat/completions",
headers={"Authorization":"Bearer YOUR_DEEPSEEK_API_KEY"},
json={
"model":"deepseek-chat",
"messages":[{"role":"user","content": prompt}]
}
)
return response.json()['choices'][0]['message']['content']
except Exception as e:
print("API 错误:", e)
return"建议:及时清除病叶,加强通风,避免高湿环境。"
# 用户数据库(实际用 MySQL + MyBatis-Plus)
users ={
"admin":{"password":"admin123","role":"admin"},
"user1":{"password":"user123","role":"user"}
}
records =[]
@app.route('/login', methods=['POST'])
deflogin():
data = request.json
username = data.get('username')
password = data.get('password')
if users.get(username)and users[username]['password']== password:
return jsonify({"success":True,"role": users[username]['role'],"username": username})
return jsonify({"success":False})
@app.route('/detect', methods=['POST'])
defdetect_image():
file= request.files['image']
username = request.form.get('username')
filename =file.filename
save_path =f"uploads/{filename}"
file.save(save_path)
# YOLO 检测
results = model(save_path)
annotated_img = results[0].plot()
output_path =f"outputs/{filename}"
cv2.imwrite(output_path, annotated_img)
# 解析结果
detections =[]
for box in results[0].boxes:
cls_id =int(box.cls.item())
conf =float(box.conf.item())
label_en = model.names[cls_id]
label_cn = class_map[label_en]
detections.append({
"label": label_cn,
"confidence":round(conf,2),
"bbox": box.xyxy[0].tolist()
})
# 获取 AI 建议
advice = get_ai_advice(detections)
# 保存记录
record ={
"id":len(records)+1,
"username": username,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"detections": detections,
"advice": advice,
"image": output_path
}
records.append(record)
# 返回 base64 图像
withopen(output_path,"rb")as f:
img_b64 = base64.b64encode(f.read()).decode()
return jsonify({
"success":True,
"detections": detections,
"advice": advice,
"image": img_b64
})
@app.route('/ai_qa', methods=['POST'])
defai_qa():
question = request.json.get('question')
prompt =f"你是农业专家,用户问:{question}。请用中文详细回答,不要使用术语堆砌。"
try:
response = requests.post(
"https://api.deepseek.com/v1/chat/completions",
headers={"Authorization":"Bearer YOUR_DEEPSEEK_API_KEY"},
json={
"model":"deepseek-chat",
"messages":[{"role":"user","content": prompt}]
}
)
return jsonify({"answer": response.json()['choices'][0]['message']['content']})
except:
return jsonify({"answer":"建议:保持田间通风,避免过度密植。"})
if __name__ =='__main__':
os.makedirs("uploads", exist_ok=True)
os.makedirs("outputs", exist_ok=True)
app.run(debug=True, port=5000)
<!-- frontend/src/views/detect.vue -->
<template>
<div class="detect-page">
<el-upload
action="/detect"
:on-success="handleSuccess"
:data="{ username: currentUser }"
:show-file-list="false"
>
<el-button type="primary">上传图片检测</el-button>
</el-upload>
<div v-if="resultImage" class="result">
<img :src="'data:image/jpeg;base64,' + resultImage" />
<p><strong>AI建议:</strong>{{ aiAdvice }}</p>
<el-button @click="exportPDF">导出报告</el-button>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import axios from 'axios'
const currentUser = 'admin' // 实际从登录获取
const resultImage = ref('')
const aiAdvice = ref('')
const handleSuccess = (response) => {
if (response.success) {
resultImage.value = response.image
aiAdvice.value = response.advice
}
}
const exportPDF = () => {
window.open(`/export_pdf/${currentRecordId}`, '_blank')
}
</script>
<style scoped>
.result { margin-top: 20px; text-align: center; }
.result img { max-width: 80%; border: 1px solid #ddd; }
</style>
best.ptwhite_spotmosaic_virustobacco_bugleaf_thick🔗 下载方式:
使用 yolo train data=tobacco.yaml epochs=300 imgsz=640训练或联系我获取预训练权重包(含 best.pt和data.yaml)
pip install flask ultralytics opencv-python requests
python app.py
cd frontend
npminstall
npm run serve
axios 调用 http://localhost:5000/detectPOST /logintrain.pydata.yaml + 预训练权重 | |