按照json文件的值复制图片

按照json文件的值复制图片

  • 文件格式
  • 处理当前JSON
  • 代码封装
  • 增加批处理

文件格式

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

0是不挑选,1是挑选

处理当前JSON

# coding: utf-8
from PIL import Image, ImageDraw, ImageFont
import os
import shutil
import cv2 as cv
import numpy as np
import jsondef read_json(file_name):with open(file_name, 'rb') as f:data = json.load(f)return datadef zhuanhuan(i):if i == 0:return "0_0.bmp"elif i == 1:return "0_1.bmp"elif i == 2:return "0_2.bmp"elif i == 3:return "0_3.bmp"elif i == 4:return "0_4.bmp"elif i == 5:return "1_0.bmp"elif i == 6:return "1_1.bmp"elif i == 7:return "1_2.bmp"elif i == 8:return "1_3.bmp"elif i == 9:return "1_4.bmp"elif i == 10:return "2_0.bmp"elif i == 11:return "2_1.bmp"elif i == 12:return "2_2.bmp"elif i == 13:return "2_3.bmp"elif i == 14:return "2_4.bmp"elif i == 15:return "3_0.bmp"elif i == 16:return "3_1.bmp"elif i == 17:return "3_2.bmp"elif i == 18:return "3_3.bmp"elif i == 19:return "3_4.bmp"elif i == 20:return "4_0.bmp"elif i == 21:return "4_1.bmp"elif i == 22:return "4_2.bmp"elif i == 23:return "4_3.bmp"elif i == 24:return "4_4.bmp"if __name__ == "__main__":path = "D:\\code\\select\\1\\"file_dict = {}select_list = []file_dict = read_json("./1/kuaisu.json")# print(file_dict)a = len(file_dict)# print(a)print(file_dict["1_1.bmp"])print(zhuanhuan(1))print("开始转换")for x in range(len(file_dict)):name = zhuanhuan(x)#print(file_dict[name])select_list.append(file_dict[name])#print(select_list)#shutil.copy("D:\\code\\select\\1\\0_0.bmp", "D:\\code\\select\\0_0.bmp")#读取数组和拷贝图片for x in range(len(select_list)):if select_list[x]==1:old_path = path+zhuanhuan(x)new_path1 = "D:\\code\\select\\final\\"new_path2 = new_path1 + zhuanhuan(x)if os.path.exists(new_path1):shutil.copy(old_path,new_path2)##print('')else:os.mkdir(new_path1)  # 创建pic文件夹,用于保存图片shutil.copy(old_path,new_path2)

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

参考1
参考2

代码封装

# coding: utf-8
from PIL import Image, ImageDraw, ImageFont
import os
import shutil
import cv2 as cv
import numpy as np
import jsondef read_json(file_name):with open(file_name, 'rb') as f:data = json.load(f)return datadef zhuanhuan(i):if i == 0:return "0_0.bmp"elif i == 1:return "0_1.bmp"elif i == 2:return "0_2.bmp"elif i == 3:return "0_3.bmp"elif i == 4:return "0_4.bmp"elif i == 5:return "1_0.bmp"elif i == 6:return "1_1.bmp"elif i == 7:return "1_2.bmp"elif i == 8:return "1_3.bmp"elif i == 9:return "1_4.bmp"elif i == 10:return "2_0.bmp"elif i == 11:return "2_1.bmp"elif i == 12:return "2_2.bmp"elif i == 13:return "2_3.bmp"elif i == 14:return "2_4.bmp"elif i == 15:return "3_0.bmp"elif i == 16:return "3_1.bmp"elif i == 17:return "3_2.bmp"elif i == 18:return "3_3.bmp"elif i == 19:return "3_4.bmp"elif i == 20:return "4_0.bmp"elif i == 21:return "4_1.bmp"elif i == 22:return "4_2.bmp"elif i == 23:return "4_3.bmp"elif i == 24:return "4_4.bmp"def my_copy(json_path,old_path,new_path):path = old_pathfile_dict = {}select_list = []file_dict = read_json(json_path)a = len(file_dict)print(file_dict["1_1.bmp"])print(zhuanhuan(1))print("开始转换")for x in range(len(file_dict)):name = zhuanhuan(x)select_list.append(file_dict[name])for x in range(len(select_list)):if select_list[x]==1:old_path = path+zhuanhuan(x)new_path1 =   new_pathnew_path2 = new_path1 + zhuanhuan(x)if os.path.exists(new_path1):shutil.copy(old_path,new_path2)else:os.mkdir(new_path1)  # 创建pic文件夹,用于保存图片shutil.copy(old_path,new_path2)if __name__ == "__main__":#my_copy("./1/kuaisu.json","D:\\code\\select\\1\\","D:\\code\\select\\final\\")my_copy

增加批处理

# coding: utf-8
from PIL import Image, ImageDraw, ImageFont
import os
import shutil
import cv2 as cv
import numpy as np
import jsondef read_json(file_name):with open(file_name, 'rb') as f:data = json.load(f)return datadef zhuanhuan(i):if i == 0:return "0_0.bmp"elif i == 1:return "0_1.bmp"elif i == 2:return "0_2.bmp"elif i == 3:return "0_3.bmp"elif i == 4:return "0_4.bmp"elif i == 5:return "1_0.bmp"elif i == 6:return "1_1.bmp"elif i == 7:return "1_2.bmp"elif i == 8:return "1_3.bmp"elif i == 9:return "1_4.bmp"elif i == 10:return "2_0.bmp"elif i == 11:return "2_1.bmp"elif i == 12:return "2_2.bmp"elif i == 13:return "2_3.bmp"elif i == 14:return "2_4.bmp"elif i == 15:return "3_0.bmp"elif i == 16:return "3_1.bmp"elif i == 17:return "3_2.bmp"elif i == 18:return "3_3.bmp"elif i == 19:return "3_4.bmp"elif i == 20:return "4_0.bmp"elif i == 21:return "4_1.bmp"elif i == 22:return "4_2.bmp"elif i == 23:return "4_3.bmp"elif i == 24:return "4_4.bmp"def my_copy(json_path,old_path,new_path):path = old_pathfile_dict = {}select_list = []file_dict = read_json(json_path)a = len(file_dict)#print(file_dict["1_1.bmp"])#print(zhuanhuan(1))#print("开始转换")for x in range(len(file_dict)):name = zhuanhuan(x)select_list.append(file_dict[name])for x in range(len(select_list)):if select_list[x]==1:old_path = path+zhuanhuan(x)new_path1 =   new_pathnew_path2 = new_path1 + zhuanhuan(x)if os.path.exists(new_path1):shutil.copy(old_path,new_path2)else:os.makedirs(new_path1)  # 创建pic文件夹,用于保存图片shutil.copy(old_path,new_path2)print(old_path)print(new_path2)print("-----------")if __name__ == "__main__":#my_copy("./1/kuaisu.json","D:\\code\\select\\1\\","D:\\code\\select\\final\\")image_root_path = "D:\标注完成"suffix = ".json"for root, dirs, files in os.walk(image_root_path):# 使用os模块获取文件夹中所有文件的路径all_files = os.listdir(root)# 筛选以指定后缀名结尾的文件filtered_files = [file for file in all_files if file.endswith(suffix)]if(len(filtered_files)):#print(root)  #当前工作文件夹json_path = root+"\\kuaisu.json"old_path = root+"\\"new_path = root.replace("标注完成","汇总")+"\\"my_copy(json_path,old_path,new_path)

在这里插入图片描述

参考1

参考2

参考3

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/93746.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux定时删除服务器日志

不说废话。直接进入操作流程 linux 定时任务是用的crontab 查看 crontab是否启动 service crond statusdead 死的 启动crontab service crond start 再次查看状态 running 运转的 查看 crontab cat /etc/crontab 查看 crontab任务 crontab -l 编辑 crontab任务 crontab …

大数据专业毕业能从事什么工作

大数据从业领域很宽广,不管是科技领域还是食品产业,零售业等都是需要大数据人才进行大数据的处理,以提供更好的用户体验,优化库存降低成本预测需求。 大数据开发做什么? 大数据开发分两类,编写Hadoop、Spa…

Java中支持分库分表的框架/组件/中间件简介

文章目录 1 sharding-jdbc2 TSharding3 Atlas4 Cobar5 MyCAT6 TDDL7 Vitess 列举一些比较常见的,简单介绍一下: sharding-jdbc(当当) TSharding(蘑菇街) Atlas(奇虎360) Cobar&#…

Vue3 学习 组合式API setup语法糖 响应式 指令 DIFF(一)

文章目录 前言一、Composition Api二、setup语法糖三、响应式refreactive 四、其他一些关键点v-prev-oncev-memov-cloak 五、虚拟Dom五、diff算法 前言 本文用于记录学习Vue3的过程 一、Composition Api 我觉得首先VUE3最大的改变就是对于代码书写的改变,从原来选择…

五子棋游戏禁手算法的改进

五子棋游戏禁手算法的改进 五子棋最新的禁手规则: 1.黑棋禁手判负、白棋无禁手。黑棋禁手有“三三”(包括“四三三”)、“四四”(包括“四四三”)和“长连”。黑棋只能以“四三”取胜。 2.黑方…

面试被打脸,数据结构底层都不知道么--回去等通知吧

数据结构之常见的8种数据结构: -数组Array -链表 Linked List -堆 heap -栈 stack -队列 Queue -树 Tree -散列表 Hash -图 Graph 数据结构-链表篇 Linklist定义: -是一种线性表,并不会按线性的顺序存储数据,即逻辑上相邻…

一种改进多旋翼无人机动态仿真的模块化仿真环境研究(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥 🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️座右铭&a…

Maven之hibernate-validator 高版本问题

hibernate-validator 高版本问题 hibernate-validator 的高版本(邮箱注解)依赖于高版本的 el-api,tomcat 8 的 el-api 是 3.0,满足需要。但是 tomcat 7 的 el-api 只有 2.2,不满足其要求。 解决办法有 2 种&#xff…

2023.9.1 简单认识 JVM

目录 JVM 内存划分 本地方法栈 虚拟机栈 程序计数器 堆区 元数据区 JVM 类加载机制 加载 验证 准备 解析 初始化 类被加载的几种情况(懒汉模式 ---> 只要被用到才会被加载) 双亲委派模型 JVM 内存划分 JVM 是一个应用程序,在…

万级数据优化EasyExcel+mybatis流式查询导出封装

文章目录 前言.万级数据优化一. 直接上流式查询封装工具代码二. 传统分页导出查询三. 流式查询概念游标查询 前言.万级数据优化 我们不妨先给大家讲一个概念,利用此概念我们正好给大家介绍一个数据库优化的小技巧: 需求如下:将一个地市表的数…

创建型模式-建造者模式

使用多个简单的对象一步一步构建成一个复杂的对象 主要解决:主要解决在软件系统中,有时候面临着"一个复杂对象"的创建工作,其通常由各个部分的子对象用一定的算法构成;由于需求的变化,这个复杂对象的各个部…

Linux内核源码分析 (5)多处理器调度

Linux内核源码分析 (5)多处理器调度 文章目录 Linux内核源码分析 (5)多处理器调度注:本章节使用的内核版本为Linux 5.6.18一、 SMT和NUMA1、SMP (对称多处理器结构)2、NUMA (非一致内存访问结构) 二、多核调度三、调度域和调度组四、SMP调度详…