import base64
import os,sys
import random
import json
import time
import datetime
import string
from flask import render_template, request, redirect, flash, url_for, session
from sqlalchemy import and_
sys.path.insert(0, os.path.abspath('..'))
from daoctor import app
from daoctor.models import *
from daoctor.机器学习.predict import img_predict
from daoctor.机器学习.识农API import 水稻识别
@app.route('/')
def MainPage():
return render_template('main.html', 当前时间=time.time())
@app.route('/backmain',methods=['GET','POST'])
def BackmainPage():
nickname = request.values.get("nickname")
print(nickname)
entry = user.query.filter(user.nickname == nickname).first()
print(entry.nickname)
return render_template('backmain.html',entry=entry)
@app.route('/upload', methods=['GET', 'POST'])
def uploader():
if request.method == 'POST':
用户ID = session["用户ID"]
f = request.files['file']
ori_path = os.path.dirname(os.path.realpath(__file__))
img_path = ori_path + '/static/shiyan.jpg'
f.save(img_path)
print(img_path)
if 用户ID == "lkz":
# 识农API
host = "http://ldttwebserver.chinanorth2.cloudapp.chinacloudapi.cn"
url = host + "/static/shiyan.jpg"
结果 = 水稻识别(url)
print(结果)
ImgIdentResult = 结果["识别结果"]
PredictAccuracy = 结果["准确率"]
else:
# 本机机器学习API
ImgIdentResult, PredictAccuracy = img_predict(img_path)
# 为查询记录增加新数据
当前使用时间 = datetime.datetime.now().strftime('%Y-%m-%d')
本次准确率 = str(PredictAccuracy) + '%'
本次推测病名 = ImgIdentResult
# 生成随机字符串作为查询ID
str_list = [random.choice(string.digits + string.ascii_letters) for i in range(5)]
# 验证是否存在
# 用户ID='隐私信息不记录到历史'#为方便知识共享让所有用户可以看到总的记录,但为了隐私在查询的历史记录保存中则不记录用户ID
# if history.query.filter(history.查询ID == (''.join(str_list))).all() == []:
# 本次查询ID = ''.join(str_list)
# print("本次查询ID", 本次查询ID)
print(f.tell())
f.seek(0) # 回到文件起始位置
# print(f.read())#f.read()和BLOB是不同的
# f.seek(0)
new_img = 'data:image/jpeg;base64,' + str(base64.b64encode(f.read()), 'utf-8')
# 从这里起,存在数据库的文件格式就是这种格式,也就是说,改成text,然后也不必在那边读取的时候进行多余的处理entry.用户上传图像就是直接可读
entry = history(本次推测病名, 当前使用时间, 用户ID, 本次准确率, new_img)
db.session.add(entry)
db.session.commit()
print(entry)
百科条目 = wiki.query.filter(wiki.病名.like('%{0}%'.format(本次推测病名))).first()
if 百科条目:
return json.dumps(
{'code': 0, 'result': ImgIdentResult, 'accuracy': PredictAccuracy, '病名': 百科条目.病名, '图片': 百科条目.图片})
# 改为返回ajax
return json.dumps({'code': 0, 'result': ImgIdentResult, 'accuracy': PredictAccuracy, '百科条目': 百科条目})
#百科的页面Controller逻辑
@app.route('/wiki/', methods=['GET', 'POST'])
@app.route('/wiki/<param>', methods=['GET', 'POST'])
def WikiPage(param=None):
print("百科传入参数:", param)
身份 = session["status"]
if param == None:
return render_template('百科/diseaseWiki.html', wiki=wiki.query.all(), 身份=身份, 当前时间=time.time())
elif param == "search":
if request.method == 'POST':
return render_template('功能页/error.html', error="Wiki Search 不能是POST")
查询病名 = request.values.get("查询病名")
return render_template('百科/diseaseWiki.html', wiki=wiki.query.filter(wiki.病名.like('%{0}%'.format(查询病名))).all(),
身份=身份, 当前时间=time.time())
elif param == "new":
if request.method == 'GET':
return render_template('百科/diseaseDetails.html', 身份=身份, 当前时间=time.time())
# POST
# if not request.form['病名'] or not request.form['危害'] or not request.form['症状']:
# return render_template('功能页/error.html',error="Wiki New 参数不全!")
# 病名, 危害, 症状,防治方式,图片,其他说明,访问次数
entry = wiki(request.form['病名'], request.form['危害'], request.form['症状'],
request.form['防治方式'], request.form['图片'],
request.form['其他说明'], request.form['访问次数'])
db.session.add(entry)
db.session.commit()
return redirect("/wiki")
elif param == "details":
if request.method == 'POST':
病名 = request.form['原病名']
editable = True
else:
病名 = request.values.get("病名")
editable = None
entry = wiki.query.filter(wiki.病名 == 病名).first()
return render_template('百科/diseaseDetails.html', entry=entry, editable=editable, 身份=身份, 当前时间=time.time())
elif param == "delete":
if request.method == 'GET':
return render_template('功能页/error.html', error="Wiki Delete 不能是GET!")
# POST
entry = wiki.query.filter(wiki.病名 == request.form['原病名']).first()
db.session.delete(entry)
db.session.commit()
return redirect("/wiki")
elif param == "update":
if request.method == 'GET':
return render_template('功能页/error.html', error="Wiki Update 不能是GET!")
# POST
oldEntry = wiki.query.filter(wiki.病名 == request.form['原病名']).first()
entry = wiki(request.form['病名'], request.form['危害'], request.form['症状'],
request.form['防治方式'], request.form['图片'],
request.form['其他说明'], request.form['访问次数'])
oldEntry.update(entry)
db.session.commit()
return render_template('百科/diseaseDetails.html', entry=entry, 身份=身份, 当前时间=time.time())
else:
return render_template('功能页/error.html', error="Wiki 没有“{0}”参数!".format(param))
# 登录
@app.route('/login', methods=['GET', 'POST'])
def LoginPage():
if (request.method == 'POST'):
nickname = request.values.get('nickname')
password = request.values.get('password')
print('nickname', nickname, 'password', password)
entry = user.query.filter(user.nickname == nickname).first()
if entry.password == password:
session["status"] = entry.status
session["用户ID"] = entry.nickname
print("LKZ: Session使用示例:", entry.status)
return render_template('index.html', entry=entry, 当前时间=time.time())
else:
return render_template('功能页/error.html', error='用户名或密码错误!')
return render_template('用户/login.html')
# 注册
@app.route('/res', methods=['GET', 'POST'])
def ResPage():
if request.method == 'POST':
nickname=request.form['nickname']
entry = user.query.filter(user.nickname == nickname).first()
if(entry!=None):
return render_template('功能页/error.html',error='该用户名已经被注册过!')
# POST
entry = user(request.form['name'], request.form['nickname'], request.form['sex'],
request.form['tel'], request.form['location'], request.form['password'], '普通用户')
db.session.add(entry)
db.session.commit()
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
python人工智能毕业设计-基于机器学习实现的农作物病虫害识别系统(源码+数据集).zip基于机器学习的农作物病虫害识别系统是利用计算机视觉和机器学习技术来自动检测和识别农作物叶片上的病虫害。这种系统可以帮助农民和专业人士及时发现和处理农作物的病虫害问题,从而提高农作物的产量和质量。 下面是基于机器学习实现农作物病虫害识别系统的一般工作流程: 1. 数据收集和预处理:收集大量的农作物病虫害图像数据,并进行预处理,包括调整图像大小、去除噪声和标准化等。 2. 数据标注:为每个图像打上相应的病虫害标签,以便训练模型进行分类。 3. 特征提取:使用图像处理技术和特征提取算法,提取图像中与病虫害相关的特征,如颜色、纹理、形状等。 4. 模型训练:使用机器学习算法,如卷积神经网络(CNN)、支持向量机(SVM)等,对标注好的图像数据进行训练,以建立分类模型。 5. 模型评估和调优:使用测试集评估训练好的模型的性能,并进行模型的调优和优化,以提高准确率和鲁棒性。 6. 系统实施:将训练好的模型嵌入到农作物病虫害识别系统中,可以是一个独立的应用程序、网站或移动应用程序。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
共 477 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- ,,,,4062024-04-28资源内容详细,总结地很全面,与描述的内容一致,对我启发很大,学习了。
- m0_751109772024-07-06超级好的资源,很值得参考学习,对我启发很大,支持!
- m0_700245422024-06-01资源值得借鉴的内容很多,那就浅学一下吧,值得下载!
- hgghcgcfdr2024-05-15资源内容总结的很到位,内容详实,很受用,学到了~
![avatar](https://profile-avatar.csdnimg.cn/6f999e5eff2040dc8aaf911dc17b4077_weixin_55305220.jpg!1)
程序员张小妍
- 粉丝: 1w+
- 资源: 3134
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)