基于Python实现简易的植物识别小系统
作者:顾木子吖 时间:2021-10-09 21:30:57
导语
"? 花草树木 皆有呈名
热爱自然,从认识自然开始 "
现在的植物爱好者,遇到不认得的植物。怎么办呢?
前几天去逛商场,一进商城一一一一门口的花店吸引了我的注意:摆放在店门口的各色鲜花植物花卉真的特别好看!
忍不住进门逛了一圈,发现我真的不认识,种类太多,对花卉的品种了解颇少。
回来之后找到了2款简单好用的植物识别APP一一一伴侣跟形色蛮好用的!
闲着也是闲着:默默用Python编写了一款简单的植物识别系统给大家正好la~
正文
1)环境安装
本文用到的环境:Python3.7? Pycharm社区版? ?模块:PyQt5。
2)主程序
import sys
from PyQt5.QtWidgets import(QWidget,QApplication,QGridLayout,QLabel,
QLineEdit,QTextEdit,QPushButton,QFrame,QFileDialog)
from PyQt5.QtGui import QPixmap
#导入baiduAPI调用模块
import request
class AIGUI(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
#关于表格类的相关初始化代码
#setSpacing 就是设置每个控件的外边框
grid=QGridLayout()
grid.setSpacing(10)
#各个控件
#1号控件
explain=QLabel('请选择您要识别的图片')
#2号 单号文本框
self.imgUrl=QLineEdit()
#3号,按钮
self.select=QPushButton("选择图片")
#为按钮添加一个事件处理函数
self.select.clicked.connect(self.openfile)
#4号,图片框
self.imgLab=QLabel("11.png")
self.imgLab.setFrameShape(QFrame.Box)
#imgLab.setFrameShadow(QFrame.Raised)
self.imgLab.setLineWidth(1)
#imgLab.setPixmap(QPixmap(""))
#5号,多行
self.info=QTextEdit()
#将控件进行合理布局
grid.addWidget(explain,1,0)
grid.addWidget(self.imgUrl,1,1)
grid.addWidget(self.select,1,2)
grid.addWidget(self.imgLab,2,0,5,3)
grid.addWidget(self.info,1,3,6,1)
#窗口最后的设置
self.setLayout(grid)
self.setGeometry(300,300,350,300)
self.setWindowTitle("植物识别小系统")
self.show()
def openfile(self):
#打开图片弹窗,选择图片
self.select_path=QFileDialog.getOpenFileName(self,"选择要识别的图片","/","Imgae Files(*.jpg *.png)")
#如果没选择图片,空过
if not self.select_path[0].strip():
pass
else:
#选择图片后执行下面的内容
# 设置图片的路径
self.imgUrl.setText(self.select_path[0])
#在图片标签框中显示图片
#1)根据路径pixmap解析图片
pixmap=QPixmap(self.select_path[0])
#2)缩放图片
scalePixmap=pixmap.scaledToWidth(300)
#scaledPixmap=pixmap.scaled(QSize(311,301))
#3)显示
self.imgLab.setPixmap(scalePixmap)
result=self.identify()
self.info.setText(result)
#借助百度AI平台完成植物识别工作
def identify(self):
result=Request.BaiduAPI(self.select_path[0])
return result
def main():
app=QApplication(sys.argv)
ai=AIGUI()
sys.exit(app.exec_())
if __name__=='__main__':
main()
3)效果展示
第一组玫瑰花:
?第二组百合花:
?
来源:https://blog.csdn.net/weixin_55822277/article/details/121303566
标签:Python,植物,识别
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
10个值得关注的优秀CSS框架
2009-05-29 18:11:00
![](https://img.aspxhome.com/file/UploadPic/20095/29/blueprint-27s.png)
php入门学习知识点三 PHP上传
2023-11-23 12:10:49
pycharm中如何使用快捷键按出代码提示框
2023-03-11 22:18:52
![](https://img.aspxhome.com/file/2023/8/84928_0s.jpg)
python自动提取文本中的时间(包含中文日期)
2023-08-22 21:32:11
python 字符串只保留汉字的方法
2022-07-15 00:34:49
Python切片操作实例分析
2022-05-02 17:49:25
关于python中readlines函数的参数hint的相关知识总结
2023-12-31 02:37:12
![](https://img.aspxhome.com/file/2023/5/63565_0s.png)
Python中序列的修改、散列与切片详解
2022-10-27 14:47:58
![](https://img.aspxhome.com/file/2023/0/104820_0s.png)
浅谈opencv自动光学检测、目标分割和检测(连通区域和findContours)
2023-04-15 09:25:18
![](https://img.aspxhome.com/file/2023/0/75890_0s.jpg)
基于Python __dict__与dir()的区别详解
2021-04-23 15:00:34
基于wxpython实现的windows GUI程序实例
2022-07-03 21:33:01
如何表示python中的相对路径
2022-09-06 14:13:41
python基础之内置函数
2022-02-28 09:15:58
![](https://img.aspxhome.com/file/2023/7/93537_0s.png)
CSS模块化设计
2009-01-05 12:10:00
Python二进制文件读取并转换为浮点数详解
2022-12-16 19:10:40
![](https://img.aspxhome.com/file/2023/0/77640_0s.png)
python教程之进程和线程
2021-09-27 02:54:00
![](https://img.aspxhome.com/file/2023/5/83725_0s.png)
Python中os模块的12种用法总结
2023-12-01 07:16:28
![](https://img.aspxhome.com/file/2023/4/79734_0s.png)
python paramiko模块学习分享
2021-11-10 16:57:00
解决杀毒软件误删asp文件的方法
2008-10-21 21:23:00
python argparse模块通过后台传递参数实例
2021-05-08 04:13:17
![](https://img.aspxhome.com/file/2023/4/121144_0s.jpg)