File size: 9,630 Bytes
10dcc2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
'''
rectify the SfM model from SIMPLE_RADIAL to PINHOLE
'''
import os

command_1 = 'colmap image_undistorter --image_path={0} --input_path={1} --output_path={2}'
command_2 = 'colmap model_converter --input_path={0} --output_path={1} --output_type=TXT'
command_3 = 'mv {0} {1}'
command_4 = 'python sort_images_txt.py --reference={0} --unordered={1} --save_to={2}'

MegaDepth_v1_SfM = '/media/jiangwei/data_ssd/MegaDepth_v1_SfM/'
assert os.path.isdir(MegaDepth_v1_SfM), 'Change to your local path'
all_scenes = [
    '0000/sparse/manhattan/0',
    '0000/sparse/manhattan/1',
    '0001/sparse/manhattan/0',
    '0002/sparse/manhattan/0',
    '0003/sparse/manhattan/0',
    '0004/sparse/manhattan/0',
    '0004/sparse/manhattan/1',
    '0004/sparse/manhattan/2',
    '0005/sparse/manhattan/0',
    '0005/sparse/manhattan/1',
    '0007/sparse/manhattan/0',
    '0007/sparse/manhattan/1',
    '0008/sparse/manhattan/0',
    '0011/sparse/manhattan/0',
    '0012/sparse/manhattan/0',
    '0013/sparse/manhattan/0',
    '0015/sparse/manhattan/0',
    '0015/sparse/manhattan/1',
    '0016/sparse/manhattan/0',
    '0017/sparse/manhattan/0',
    '0019/sparse/manhattan/0',
    '0019/sparse/manhattan/1',
    '0020/sparse/manhattan/0',
    '0020/sparse/manhattan/1',
    '0021/sparse/manhattan/0',
    '0022/sparse/manhattan/0',
    '0023/sparse/manhattan/0',
    '0023/sparse/manhattan/1',
    '0024/sparse/manhattan/0',
    '0025/sparse/manhattan/0',
    '0025/sparse/manhattan/1',
    '0026/sparse/manhattan/0',
    '0027/sparse/manhattan/0',
    '0032/sparse/manhattan/0',
    '0032/sparse/manhattan/1',
    '0033/sparse/manhattan/0',
    '0034/sparse/manhattan/0',
    '0035/sparse/manhattan/0',
    '0036/sparse/manhattan/0',
    '0037/sparse/manhattan/0',
    '0039/sparse/manhattan/0',
    '0041/sparse/manhattan/0',
    '0041/sparse/manhattan/1',
    '0042/sparse/manhattan/0',
    '0043/sparse/manhattan/0',
    '0044/sparse/manhattan/0',
    '0046/sparse/manhattan/0',
    '0046/sparse/manhattan/1',
    '0046/sparse/manhattan/2',
    '0047/sparse/manhattan/0',
    '0048/sparse/manhattan/0',
    '0049/sparse/manhattan/0',
    '0050/sparse/manhattan/0',
    '0056/sparse/manhattan/0',
    '0057/sparse/manhattan/0',
    '0058/sparse/manhattan/0',
    '0058/sparse/manhattan/1',
    '0060/sparse/manhattan/0',
    '0061/sparse/manhattan/0',
    '0062/sparse/manhattan/0',
    '0062/sparse/manhattan/1',
    '0063/sparse/manhattan/0',
    '0063/sparse/manhattan/1',
    '0063/sparse/manhattan/2',
    '0063/sparse/manhattan/3',
    '0064/sparse/manhattan/0',
    '0065/sparse/manhattan/0',
    '0067/sparse/manhattan/0',
    '0070/sparse/manhattan/0',
    '0071/sparse/manhattan/0',
    '0071/sparse/manhattan/1',
    '0076/sparse/manhattan/0',
    '0078/sparse/manhattan/0',
    '0080/sparse/manhattan/0',
    '0083/sparse/manhattan/0',
    '0086/sparse/manhattan/0',
    '0087/sparse/manhattan/0',
    '0087/sparse/manhattan/1',
    '0090/sparse/manhattan/0',
    '0092/sparse/manhattan/0',
    '0092/sparse/manhattan/1',
    '0094/sparse/manhattan/0',
    '0095/sparse/manhattan/0',
    '0095/sparse/manhattan/1',
    '0095/sparse/manhattan/2',
    '0098/sparse/manhattan/0',
    '0099/sparse/manhattan/0',
    '0100/sparse/manhattan/0',
    '0101/sparse/manhattan/0',
    '0102/sparse/manhattan/0',
    '0103/sparse/manhattan/0',
    '0104/sparse/manhattan/0',
    '0104/sparse/manhattan/1',
    '0105/sparse/manhattan/0',
    '0107/sparse/manhattan/0',
    '0115/sparse/manhattan/0',
    '0117/sparse/manhattan/0',
    '0117/sparse/manhattan/1',
    '0117/sparse/manhattan/2',
    '0121/sparse/manhattan/0',
    '0121/sparse/manhattan/1',
    '0122/sparse/manhattan/0',
    '0129/sparse/manhattan/0',
    '0130/sparse/manhattan/0',
    '0130/sparse/manhattan/1',
    '0130/sparse/manhattan/2',
    '0133/sparse/manhattan/0',
    '0133/sparse/manhattan/1',
    '0137/sparse/manhattan/0',
    '0137/sparse/manhattan/1',
    '0137/sparse/manhattan/2',
    '0141/sparse/manhattan/0',
    '0143/sparse/manhattan/0',
    '0147/sparse/manhattan/0',
    '0147/sparse/manhattan/1',
    '0148/sparse/manhattan/0',
    '0148/sparse/manhattan/1',
    '0149/sparse/manhattan/0',
    '0150/sparse/manhattan/0',
    '0151/sparse/manhattan/0',
    '0156/sparse/manhattan/0',
    '0160/sparse/manhattan/0',
    '0160/sparse/manhattan/1',
    '0160/sparse/manhattan/2',
    '0162/sparse/manhattan/0',
    '0162/sparse/manhattan/1',
    '0168/sparse/manhattan/0',
    '0175/sparse/manhattan/0',
    '0176/sparse/manhattan/0',
    '0176/sparse/manhattan/1',
    '0176/sparse/manhattan/2',
    '0177/sparse/manhattan/0',
    '0178/sparse/manhattan/0',
    '0178/sparse/manhattan/1',
    '0181/sparse/manhattan/0',
    '0183/sparse/manhattan/0',
    '0185/sparse/manhattan/0',
    '0186/sparse/manhattan/0',
    '0189/sparse/manhattan/0',
    '0190/sparse/manhattan/0',
    '0197/sparse/manhattan/0',
    '0200/sparse/manhattan/0',
    '0200/sparse/manhattan/1',
    '0204/sparse/manhattan/0',
    '0204/sparse/manhattan/1',
    '0205/sparse/manhattan/0',
    '0205/sparse/manhattan/1',
    '0209/sparse/manhattan/1',
    '0212/sparse/manhattan/0',
    '0212/sparse/manhattan/1',
    '0214/sparse/manhattan/0',
    '0214/sparse/manhattan/1',
    '0217/sparse/manhattan/0',
    '0223/sparse/manhattan/0',
    '0223/sparse/manhattan/1',
    '0223/sparse/manhattan/2',
    '0224/sparse/manhattan/0',
    '0224/sparse/manhattan/1',
    '0229/sparse/manhattan/0',
    '0231/sparse/manhattan/0',
    '0235/sparse/manhattan/0',
    '0237/sparse/manhattan/0',
    '0238/sparse/manhattan/0',
    '0240/sparse/manhattan/0',
    '0243/sparse/manhattan/0',
    '0252/sparse/manhattan/0',
    '0257/sparse/manhattan/0',
    '0258/sparse/manhattan/0',
    '0265/sparse/manhattan/0',
    '0265/sparse/manhattan/1',
    '0269/sparse/manhattan/0',
    '0269/sparse/manhattan/1',
    '0269/sparse/manhattan/2',
    '0271/sparse/manhattan/0',
    '0275/sparse/manhattan/0',
    '0277/sparse/manhattan/0',
    '0277/sparse/manhattan/1',
    '0281/sparse/manhattan/0',
    '0285/sparse/manhattan/0',
    '0286/sparse/manhattan/0',
    '0286/sparse/manhattan/1',
    '0290/sparse/manhattan/0',
    '0290/sparse/manhattan/1',
    '0294/sparse/manhattan/0',
    '0299/sparse/manhattan/0',
    '0303/sparse/manhattan/0',
    '0306/sparse/manhattan/0',
    '0307/sparse/manhattan/0',
    '0312/sparse/manhattan/0',
    '0312/sparse/manhattan/1',
    '0323/sparse/manhattan/0',
    '0326/sparse/manhattan/0',
    '0327/sparse/manhattan/0',
    '0327/sparse/manhattan/1',
    '0327/sparse/manhattan/2',
    '0331/sparse/manhattan/0',
    '0335/sparse/manhattan/0',
    '0335/sparse/manhattan/1',
    '0341/sparse/manhattan/0',
    '0341/sparse/manhattan/1',
    '0348/sparse/manhattan/0',
    '0349/sparse/manhattan/0',
    '0349/sparse/manhattan/1',
    '0360/sparse/manhattan/0',
    '0360/sparse/manhattan/1',
    '0360/sparse/manhattan/2',
    '0366/sparse/manhattan/0',
    '0377/sparse/manhattan/0',
    '0380/sparse/manhattan/0',
    '0387/sparse/manhattan/0',
    '0389/sparse/manhattan/0',
    '0389/sparse/manhattan/1',
    '0394/sparse/manhattan/0',
    '0394/sparse/manhattan/1',
    '0402/sparse/manhattan/0',
    '0402/sparse/manhattan/1',
    '0406/sparse/manhattan/0',
    '0407/sparse/manhattan/0',
    '0411/sparse/manhattan/0',
    '0411/sparse/manhattan/1',
    '0412/sparse/manhattan/0',
    '0412/sparse/manhattan/1',
    '0412/sparse/manhattan/2',
    '0430/sparse/manhattan/0',
    '0430/sparse/manhattan/1',
    '0430/sparse/manhattan/2',
    '0443/sparse/manhattan/0',
    '0446/sparse/manhattan/0',
    '0455/sparse/manhattan/0',
    '0472/sparse/manhattan/0',
    '0472/sparse/manhattan/1',
    '0474/sparse/manhattan/0',
    '0474/sparse/manhattan/1',
    '0474/sparse/manhattan/2',
    '0476/sparse/manhattan/0',
    '0476/sparse/manhattan/1',
    '0476/sparse/manhattan/2',
    '0478/sparse/manhattan/0',
    '0478/sparse/manhattan/1',
    '0482/sparse/manhattan/0',
    '0493/sparse/manhattan/0',
    '0493/sparse/manhattan/1',
    '0494/sparse/manhattan/1',
    '0496/sparse/manhattan/0',
    '0505/sparse/manhattan/0',
    '0559/sparse/manhattan/0',
    '0733/sparse/manhattan/0',
    '0733/sparse/manhattan/1',
    '0768/sparse/manhattan/0',
    '0860/sparse/manhattan/0',
    '0860/sparse/manhattan/1',
    '1001/sparse/manhattan/0',
    '1017/sparse/manhattan/0',
    '1589/sparse/manhattan/0',
    '3346/sparse/manhattan/0',
    '4541/sparse/manhattan/0',
    '5000/sparse/manhattan/0',
    '5001/sparse/manhattan/0',
    '5002/sparse/manhattan/0',
    '5003/sparse/manhattan/0',
    '5004/sparse/manhattan/0',
    '5005/sparse/manhattan/0',
    '5006/sparse/manhattan/0',
    '5007/sparse/manhattan/0',
    '5008/sparse/manhattan/0',
    '5009/sparse/manhattan/0',
    '5010/sparse/manhattan/0',
    '5011/sparse/manhattan/0',
    '5012/sparse/manhattan/0',
    '5013/sparse/manhattan/0',
    '5014/sparse/manhattan/0',
    '5015/sparse/manhattan/0',
    '5016/sparse/manhattan/0',
    '5017/sparse/manhattan/0',
    '5018/sparse/manhattan/0',
]

with open('rectify.sh', "w") as fid:
    for s in all_scenes:
        s = os.path.join(MegaDepth_v1_SfM, s)
        new_dir = s + '_rectified'
        img_dir = s[:s.find('sparse')] + 'images'
        fid.write(command_1.format(img_dir, s, new_dir) + '\n')
        fid.write(command_2.format(new_dir + '/sparse', new_dir + '/sparse') + '\n')
        fid.write(command_3.format(new_dir + '/sparse/images.txt', new_dir + '/sparse/unorder_images.txt') + '\n')
        fid.write(command_4.format(s + '/images.txt', new_dir + '/sparse/unorder_images.txt', new_dir + '/sparse/images.txt') + '\n')