-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprepare_sysu.py
235 lines (218 loc) · 7.45 KB
/
prepare_sysu.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"""
Copyright (C) 2019 NVIDIA Corporation. All rights reserved.
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
"""
import os
from shutil import copyfile
# You only need to change this line to your dataset download path
download_path = 'data/sysu'
if not os.path.isdir(download_path):
print('please change the download_path')
save_path = download_path + '/ir_modify'
if not os.path.isdir(save_path):
os.mkdir(save_path)
#-----------------------------------------
#query
# query_path = download_path + '/query'
query_save_path = download_path + '/ir_modify/query'
if not os.path.isdir(query_save_path):
os.mkdir(query_save_path)
#######################
data_path=download_path
ir_cameras = ['cam3','cam6']
test_file_path = os.path.join(data_path,'exp/test_id.txt')
files_rgb = []
files_ir = []
files_test=[]
with open(test_file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids = ["%04d" % x for x in ids]
for id in sorted(ids):
n=0
for cam in ir_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
for single in os.listdir(img_dir):
if n < 4:
files_ir.append(img_dir+'/'+single)
else:
files_test.append(img_dir+'/'+single)
n=n+1
# new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
# files_ir.extend(new_files)
# print(files_ir)
for file_path in files_ir:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = query_save_path
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
for file_path in files_test:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = download_path + '/ir_modify/bounding_box_test'
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
print(dst_path + '/' + name)
############################
query_save_path = download_path + '/ir_modify/bounding_box_train'
if not os.path.isdir(query_save_path):
os.mkdir(query_save_path)
#######################
data_path=download_path
ir_cameras = ['cam3','cam6']
# rgb_cameras = ['cam1','cam2','cam3','cam4','cam5','cam6']
test_file_path = os.path.join(data_path,'exp/train_id.txt')
file_path_val = os.path.join(data_path,'exp/val_id.txt')
files_rgb = []
files_ir = []
with open(test_file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids_train = ["%04d" % x for x in ids]
with open(file_path_val, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
id_val = ["%04d" % x for x in ids]
# print(id_val)
ids_train.extend(id_val)
for id in sorted(ids_train):
for cam in ir_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
files_ir.extend(new_files)
# print(files_ir)
############################
for file_path in files_ir:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = query_save_path
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
print(dst_path + '/' + name)
print(len(files_ir))
#-------------------------------------------------------
save_path = download_path + '/rgb_modify'
if not os.path.isdir(save_path):
os.mkdir(save_path)
#-----------------------------------------
#query
# query_path = download_path + '/query'
query_save_path = download_path + '/rgb_modify/query'
if not os.path.isdir(query_save_path):
os.mkdir(query_save_path)
#######################
data_path=download_path
ir_cameras = ['cam1','cam2','cam4','cam5']
test_file_path = os.path.join(data_path,'exp/test_id.txt')
files_rgb = []
files_ir = []
files_test=[]
with open(test_file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids = ["%04d" % x for x in ids]
for id in sorted(ids):
n=0
for cam in ir_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
for single in os.listdir(img_dir):
if n < 4:
files_ir.append(img_dir+'/'+single)
else:
files_test.append(img_dir+'/'+single)
n=n+1
# new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
# files_ir.extend(new_files)
# print(files_ir)
for file_path in files_ir:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = query_save_path
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
print(dst_path + '/' + name)
for file_path in files_test:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = download_path + '/rgb_modify/bounding_box_test'
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
print(dst_path + '/' + name)
############################
query_save_path = download_path + '/rgb_modify/bounding_box_train'
if not os.path.isdir(query_save_path):
os.mkdir(query_save_path)
#######################
data_path=download_path
ir_cameras = ['cam1','cam2','cam4','cam5']
# rgb_cameras = ['cam1','cam2','cam3','cam4','cam5','cam6']
test_file_path = os.path.join(data_path,'exp/train_id.txt')
file_path_val = os.path.join(data_path,'exp/val_id.txt')
files_rgb = []
files_ir = []
with open(test_file_path, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
ids_train = ["%04d" % x for x in ids]
with open(file_path_val, 'r') as file:
ids = file.read().splitlines()
ids = [int(y) for y in ids[0].split(',')]
id_val = ["%04d" % x for x in ids]
# print(id_val)
ids_train.extend(id_val)
for id in sorted(ids_train):
for cam in ir_cameras:
img_dir = os.path.join(data_path,cam,id)
if os.path.isdir(img_dir):
new_files = sorted([img_dir+'/'+i for i in os.listdir(img_dir)])
files_ir.extend(new_files)
# print(files_ir)
print(len(files_ir))
############################
for file_path in files_ir:
file_list = file_path.split('/')
ID = file_list[-2]
c_id = 'c'+file_list[-3][-1]
img_name = file_list[-1]
# print(file_list)
src_path = file_path
dst_path = query_save_path
if not os.path.isdir(dst_path):
os.mkdir(dst_path)
name = ID+"_"+c_id+"_"+img_name
copyfile(src_path, dst_path + '/' + name)
print(dst_path + '/' + name)