当前位置: 首页 > news >正文

【Python编程】将同一种图片分类到同一文件夹中

一、数据结构如下:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、编程工具:Jupyter-Notebook

三、代码:

import os
import cv2
import shutilpath0=os.getcwd()+'\\apple\\RGB'
path1=os.getcwd()+'\\apple\\tof_confidence'
path2=os.getcwd()+'\\apple\\tof_depth'
path3=os.getcwd()+'\\apple\\tof_depthRGB'
path4=os.getcwd()+'\\apple\\tof_points'
path5=os.getcwd()+'\\apple\\tof_intensity'if not os.path.exists(path0):os.makedirs(path0)
if not os.path.exists(path1):os.makedirs(path1)
if not os.path.exists(path2):os.makedirs(path2)
if not os.path.exists(path3):os.makedirs(path3)
if not os.path.exists(path4):os.makedirs(path4)
if not os.path.exists(path5):os.makedirs(path5)path6=r'E:\Jupyter-Notebook\Apple-1'
folders=os.listdir(path6)
print(folders)c_num = 1
dr_num =1
i_num = 1
r_num = 1
d_num = 1
p_num = 1for folder in folders:path7=path6+'/'+folderfd=os.listdir(path7)print(fd)for f in fd:path8=path7+'/'+fimages=os.listdir(path8)for image in images:if image.startswith('confidence'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'E:\Jupyter-Notebook\apple\tof_confidence\no'+ str(c_num) + '.png', img)c_num += 1elif image.startswith('depthRGB'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'E:\Jupyter-Notebook\apple\tof_depthRGB\no'+ str(dr_num) + '.png', img)dr_num += 1elif image.startswith('intensity'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'E:\Jupyter-Notebook\apple\tof_intensity\no'+ str(i_num) + '.png', img)i_num += 1elif image.startswith('RGB'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'E:\Jupyter-Notebook\apple\RGB\no'+ str(r_num) + '.png', img)r_num += 1elif image.startswith('depth.png'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'E:\Jupyter-Notebook\apple\tof_depth\no'+ str(d_num) + '.png', img)d_num += 1elif image.endswith('.pcd'):img=path8+'/'+imageshutil.copy(img,r'E:\Jupyter-Notebook\apple\tof_points\no'+ str(p_num) + '.pcd')p_num +=1

注:代码文件与图片文件同处一个文件夹,如上例,在Jupyter-Notebook文件夹
在这里插入图片描述

http://www.lryc.cn/news/144554.html

相关文章:

  • Web安全测试(四):XML注入和代码注入
  • 如何通过内网穿透实现外部网络对Spring Boot服务端接口的HTTP监听和调试?
  • 深入理解c++特殊成员函数
  • RecyclerView面试问答
  • Redis 7 教程 数据持久化
  • 【ArcGIS微课1000例】0072:如何生成空间权重矩阵
  • 【芯片设计封装与测试】芯片测试目的、方法、分类及案例
  • k8s集群证书过期解决
  • Linux学习之Ubuntu 20.04在github下载源码安装Openresty 1.19.3.1
  • bootloader串口更新程序[瑕疵学习板]
  • 浅谈视频汇聚平台EasyCVR视频平台在城市安全综合监测预警台风天气中的重要作用
  • GaussDB技术解读系列:高级压缩之OLTP表压缩
  • 管理类联考——英语二——实战篇——大作文——图表——静态图表——第一段
  • https 的ssl证书过期处理解决方案(lighthttpd)
  • 【java】【idea2023版】Springboot模块没有.iml文件的问题
  • Qt QScrollArea使用
  • Unity3d:GameFramework解析:实体,对象池,资源管理,获取计数,引用计数,自动释放
  • Django基础6——数据模型关系
  • 【chrome扩展开发】如何在项目中判断插件是否已安装
  • Centos 7.6 安装mongodb
  • Ubuntu下安装nginx服务,实现通过URL读取ubuntu下图片
  • 本地部署 Stable Diffusion(Mac 系统)
  • 浪潮云海护航省联社金融上云,“一云多芯”赋能数字农业
  • MyCat的XA事务研究及字符集问题
  • 9、监测数据采集物联网应用开发步骤(7)
  • 微信小程序开发教学系列(9)- 小程序页面优化
  • 如何将储存在Mac或PC端的PDF文件传输到移动设备呢?
  • 一图看懂架构划分原则:技术划分 OR 领域划分?
  • 从零开始的Hadoop学习(二)| Hadoop介绍、优势、组成、HDFS架构
  • 问道管理:逾4600股飘红!汽车板块爆了,多股冲击涨停!