首页 > 分享 > python识别花卉种类并自动整理分类

python识别花卉种类并自动整理分类

# -*- coding: utf-8 -*- # 作者:朱小五 # 公众号:快学Python # 微信联系:zpw505 # 代码仅供学习参考,不可商用,转发不得删除此处信息 import os import base64 import requests import shutil import time API_Key = '1ZWO1lBujdAWPP3uFEzkxjFg' Secret_Key = 'sp0ntMZdyoOkYXtGkzg2aN0hyAyB0zoN' def get_access_token(API_Key,Secret_Key): host = f"https://aip.baidubce.com/oauth/2.0/token?client_secret={Secret_Key}&grant_type=client_credentials&client_id={API_Key}" response = requests.get(host) return response.json()['access_token'] access_token = get_access_token(API_Key,Secret_Key) def get_fname(file_flower): request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant" # 二进制方式打开图片文件 f = open(f'{path}{file_flower}', 'rb') img = base64.b64encode(f.read()) f.close() params = {"image": img} # access_token = '[调用鉴权接口获取的token]' request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) flower_name = response.json()['result'][0]['name'] return flower_name import os import shutil import time path = "./花卉合集" filenames = os.listdir(path) for i in filenames: flower_name = get_fname(i) file_path = os.path.join(path,i) folder_path = os.path.join(path,flower_name) if not os.path.exists(folder_path): os.mkdir(folder_path) shutil.move(file_path,folder_path) time.sleep(1) print("已完成识别,并整理分类")

相关知识

Python识别花卉种类,并自动整理分类!
Python 识别花卉种类,并自动整理分类!
用Python识别花卉种类,并自动整理分类!
python识别花卉种类并自动整理分类
这个好玩!用Python识别花卉种类,并自动整理分类!
Python实现识别花卉种类的示例代码
基于python编程的五种鲜花识别
花卉识别python
python 花卉识别系统 用python搭建一个花卉识别系统(IT技术)
人工智能毕业设计基于python的花朵识别系统

网址: python识别花卉种类并自动整理分类 https://m.huajiangbk.com/newsview294941.html

所属分类:花卉
上一篇: 田园风格的花园餐厅设计 美景与美
下一篇: 超千类花卉产品汇聚 全球头部品牌