当前位置:首页>农业>智慧农业基于 YOLO+DeepSeek 烟草叶病虫害检测系统 4类病虫害检测 结合大模型提供 AI 建议YOLO+DeepSeek+Pytorch+SpringBoot+Flask+Vue

智慧农业基于 YOLO+DeepSeek 烟草叶病虫害检测系统 4类病虫害检测 结合大模型提供 AI 建议YOLO+DeepSeek+Pytorch+SpringBoot+Flask+Vue

  • 2026-10-25 00:45:26
智慧农业基于 YOLO+DeepSeek 烟草叶病虫害检测系统 4类病虫害检测 结合大模型提供 AI 建议YOLO+DeepSeek+Pytorch+SpringBoot+Flask+Vue

烟草叶病虫害检测系统
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 可选


✅ 一、系统功能概述

功能
说明
📸 图片检测
单张图片上传检测
📁 批量检测
支持文件夹批量处理
🎥 视频/摄像头检测
实时视频流分析
🤖 AI 建议
调用 DeepSeek/Qwen 提供防治建议
💬 智能问答
用户可提问“怎么治?”等,AI 回答
👤 用户权限
管理员查看全部记录,普通用户仅看自己
📊 数据可视化
使用 ECharts 展示检测统计
🎨 主题自定义
支持颜色、布局、组件大小修改

✅ 二、目录结构(简化版)

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       # 依赖

✅ 三、后端核心代码(Flask 版本)

# 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)

✅ 四、前端核心代码(Vue3 + Element Plus)

<!-- 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>

✅ 五、训练好的 YOLO 权重文件

  • best.pt
    :已训练 300 epoch,精度 mAP@0.5 > 90%,包含 4 类:
    • white_spot
      (白星病)
    • mosaic_virus
      (花叶病)
    • tobacco_bug
      (烟青虫)
    • leaf_thick
      (叶厚病)

🔗 下载方式:

  1. 使用 yolo train data=tobacco.yaml epochs=300 imgsz=640 训练
  2. 或联系我获取预训练权重包(含 best.pt 和 data.yaml)

✅ 六、部署教程(简要)

1. 安装依赖

pip install flask ultralytics opencv-python requests

2. 启动服务

python app.py

3. 前端运行

cd frontend
npminstall
npm run serve

4. 接口对接

  • 前端通过 axios 调用 http://localhost:5000/detect
  • 登录接口:POST /login

✅ 七、附加资源(下单后提供)

资源
内容
✅ 数据集
整理好的 YOLO 格式数据集(含 1000+ 张图像,4 类标注)
✅ 训练代码
train.py
 + data.yaml + 预训练权重
✅ 部署文档
Docker + Nginx + MySQL 部署指南
✅ 视频检测
支持摄像头实时检测(OpenCV + Flask)
✅ AI 建议模板
白星病、花叶病等 4 种病害的专业防治建议库
✅ 可视化图表
ECharts 统计图代码(柱状图、饼图、雷达图)
✅ 用户权限控制
MySQL 表结构 + Java/SpringBoot 实现(可选)

✅ 八、技术亮点

  • 🌱 精准识别:YOLOv8 实现高精度病虫害检测
  • 🤖 智能建议:DeepSeek/Qwen 提供专业防治方案
  • 📊 数据驱动:ECharts 实时统计分析
  • 🛠️ 易扩展:模块化设计,支持新增病害类型
  • 🌐 跨平台:Web + 移动端可用
以上文字及代码仅供参考。
半价群698¥,高级VIP至尊群9900¥。

最新文章

随机文章