-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch_unzip.py
More file actions
75 lines (63 loc) · 2.18 KB
/
batch_unzip.py
File metadata and controls
75 lines (63 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
# @Time : 2022/4/12 13:55
# @Author : beyoung
# @Email : linbeyoung@stu.pku.edu.cn
# @File : cut_video.py
import os
import cv2
import argparse
def batch_unzip(ip_path, op_path):
"""
本函数可以将ip_path下所有tif结尾图片的长宽缩成原本的0.2, 并保存在op_path中
:param ip_path:
:param op_path:
:param resize_ratio:
:return:
"""
#批量缩放
# resize_ratio = 0.2
if not os.path.exists(op_path):
os.makedirs(op_path)
for filename in os.listdir(ip_path):
if filename.endswith('.tip'):
print(ip_path + filename)
zip_pth = os.path.join(ip_path, filename)
os.system(f'unzip {zip_pth} -d {op_path}')
def batch_cp(ip_path, op_path):
"""
本函数可以将ip_path下所有tif结尾图片的长宽缩成原本的0.2, 并保存在op_path中
:param ip_path:
:param op_path:
:param resize_ratio:
:return:
"""
#批量缩放
# resize_ratio = 0.2
if not os.path.exists(op_path):
os.makedirs(op_path)
for curDir, dirs, files in os.walk(ip_path):
for file in files:
if file.endswith(".tif"):
zip_pth = os.path.join(curDir, file)
print(os.path.join(curDir, file))
# print(ip_path + filename)
os.system(f'cp {zip_pth} {op_path}')
def batch_rename(path):
# 批量重命名
for filename in os.listdir(path):
im = cv2.imread(filename)
name = filename.split('.')
# print(name[1])
if name[1] == "tif":
os.rename(os.path.join(path, filename), os.path.join(path, name[0] + '.tif'))
if __name__ == '__main__':
# Parse arguments
# parser = argparse.ArgumentParser()
# parser.add_argument("--ip_path", type=str, help="原路径")
# parser.add_argument("--op_path", type=str, help="压缩后输出路径")
# parser.add_argument("--resize_ratio", type=int, default=0.2, help="压缩比例")
# args = parser.parse_args()
ip_path = '/disks/sdb/euphoria/Shuju_AnCn'
op_path = '/disks/sdb/euphoria/Shuju_AnCn_total'
# batch_unzip(args.ip_path, args.op_path)
batch_cp(ip_path, op_path)