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

【Python编程】将同一种图片分类到同一文件夹下,并且将其分类的路径信息写成txt文件进行保存

注:数据结构同上一篇博文类似

一、代码

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:\Date_Set_Apple\2022_9'
folders=os.listdir(path6)
print(folders)# d_num = 0
# dr_num =0
# i_num = 0
# p_num = 0r_num = 0
c_num = 0for 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('RGB'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'C:\Users\Hasee\apple\apple\RGB\no'+ str(r_num) + '.png', img)m= open('rgb_confidence.txt', 'a')  # 没有则创建txt文件,与代码文件同目录m.write("confidence图对应的RGB图:"+'no'+str(r_num)+"   "+folder+"    "+f+"   "+image + '\n')m.close()r_num += 1elif image.startswith('confidence'):img=cv2.imread(path8+"/"+image)cv2.imshow('img',img)cv2.waitKey(1)cv2.destroyAllWindows()cv2.imwrite(r'C:\Users\Hasee\apple\apple\tof_confidence\no'+ str(c_num) + '.png', img)m= open('rgb_confidence.txt', 'a')  # 没有则创建txt文件,与代码文件同目录m.write("RGB图对应的confidence图:"+'no'+str(c_num)+"   "+folder+"    "+f+"   "+image + '\n')m.close()c_num += 1#                 elif image.startswith('depthRGB'):
#                     img=cv2.imread(path8+"/"+image)
#                     cv2.imshow('img',img)
#                     cv2.waitKey(1)
#                     cv2.destroyAllWindows()
#                     cv2.imwrite(r'C:\Users\Hasee\apple\apple\tof_depthRGB\no'+ str(dr_num) + '.png', img)
#                     dr_num += 1#                 elif image.startswith('intensity'):
#                     img=cv2.imread(path8+"/"+image)
#                     cv2.imshow('img',img)
#                     cv2.waitKey(1)
#                     cv2.destroyAllWindows()
#                     cv2.imwrite(r'C:\Users\Hasee\apple\apple\tof_intensity\no'+ str(i_num) + '.png', img)
#                     i_num += 1#                 elif image.startswith('depth.png'):
#                     img=cv2.imread(path8+"/"+image)
#                     cv2.imshow('img',img)
#                     cv2.waitKey(1)
#                     cv2.destroyAllWindows()
#                     cv2.imwrite(r'C:\Users\Hasee\apple\apple\tof_depth\no'+ str(d_num) + '.png', img)
#                     d_num += 1#                 elif image.endswith('.pcd'):
#                     img=path8+'/'+image
#                     shutil.copy(img,r'C:\Users\Hasee\apple\apple\tof_points\no'+ str(p_num) + '.pcd')
#                     p_num +=1

二、结果展示:

在这里插入图片描述

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

相关文章:

  • 单例模式的相关知识
  • vue问题相关记录
  • skywalking服务部署
  • 【uni-app】压缩图片并添加水印
  • 《每天十分钟》-红宝书第4版-变量、作用域与内存
  • NFTScan | 08.21~08.27 NFT 市场热点汇总
  • 【Java 中级】一文精通 Spring MVC - 数据验证(七)
  • css奇数偶数选择器
  • 【算法】双指针求解盛最多水的容器
  • 浅析SAS协议:设备接入与探测
  • RISC-V IOPMP实际用例-Andes SoC‘s Rapid-k模型
  • 【高阶数据结构】哈希表详解
  • C#与西门子PLC1500的ModbusTcp服务器通信4--搭建ModbusTcp客户端
  • 性能调优篇 二、Jvm监控及诊断工具-命令行篇
  • Fooocus启动时modules报错的解决方法
  • RSA私钥解密操作
  • 数据库基本知识
  • 使用Redis统计网站的UV/DAU
  • 【python】报错:ImportError: DLL load failed: 找不到指定的模块 的详细解决办法
  • SemrushBot蜘蛛爬虫屏蔽方式
  • 6 ssh面密登录
  • 基于微信小程序的汽车租赁系统的设计与实现ljx7y
  • 优化学习体验的在线考试系统
  • 1267. 统计参与通信的服务器
  • 【考研数学】矩阵、向量与线性方程组解的关系梳理与讨论
  • 打造个人的NAS云存储-通过Nextcloud搭建私有云盘实现公网远程访问
  • FFI绕过disable_functions
  • 53 个 CSS 特效 2
  • ubuntu学习(六)----文件编程实现cp指令
  • wireshark过滤器的使用