-
Notifications
You must be signed in to change notification settings - Fork 1
/
pathname (3).py
76 lines (69 loc) · 2.29 KB
/
pathname (3).py
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
75
import os
import random
import shutil
import numpy as np
from PIL import Image
import shutil
# path1 = './datadml/kth2b/4/test/'
# path2 = './datadml/kth2b/4/train/'
# dirlist = os.listdir(path1)
# print(dirlist)
# for i in range(len(dirlist)):
# newpath = './datadml/kth2b/4/train/' + dirlist[i]
# isExists = os.path.exists(newpath)
#
# # 判断结果
# # 如果不存在则创建目录
# # 创建目录操作函数
# if not isExists:
# os.makedirs(newpath)
# print(newpath + ':创建成功')
# # return True
# else:
# # 如果目录存在则不创建,并提示目录已存在
# print(newpath + ':目录已存在')
floadername = ['sample_a','sample_b','sample_c','sample_d']
# for cg in range(len(dirlist)):
# oname = path1 + dirlist[cg] + '/' + floadername[3] + '/'
# nname = path2 + dirlist[cg] + '/'
# shutil.move(oname,nname)
# filename='data_batch_1.mat';
# data=[];
# labels=[];
# for i=1:5
# file=matfile(filename);
# data=[data;file.data];
# labels=[labels;file.labels];
# filename(12)=int2str(i+1);
# end
# save('train.mat','data','labels')
path1 = './datadml/kth2b/4/test/'
path2 = './datadml/kth2b/4/train/'
dirlist = os.listdir(path2)
print(dirlist)
# for i in range(len(dirlist)):
# ooo = path2 + dirlist[i] + '/' + floadername[3] + '/'
# ccc = path2 + dirlist[i] + '/'
# for roots, dirs, files in os.walk(ooo):
# print(files)
# for imgname in files:
# imgpath = ooo + imgname
# # im = Image.open(imgpath)
# # im = Image.open(imgpath).convert("RGB")
# # im.save(newpath + imgname)
# # os.remove(imgpath) # 转移完后删除原图片
# shutil.move(imgpath, ccc)
# os.rmdir(ooo)
for i in range(len(dirlist)):
ooo = path1 + dirlist[i] + '/' + floadername[2] + '/'
ccc = path1 + dirlist[i] + '/'
for roots, dirs, files in os.walk(ooo):
print(files)
for imgname in files:
imgpath = ooo + imgname
# im = Image.open(imgpath)
# im = Image.open(imgpath).convert("RGB")
# im.save(newpath + imgname)
# os.remove(imgpath) # 转移完后删除原图片
shutil.move(imgpath, ccc)
os.rmdir(ooo)