|
1 | 1 | import os
|
2 | 2 | import shutil
|
3 |
| - |
4 |
| -def combine_files(base_folder_1, base_folder_2): |
| 3 | +import os.path as osp |
| 4 | +def combine_files(in_folder, out_folder): |
5 | 5 | count = 0
|
6 | 6 | # Iterate through scenes in the first base folder
|
7 |
| - for scene in os.listdir(base_folder_1): |
8 |
| - scene_path_1 = os.path.join(base_folder_1, scene) |
9 |
| - scene_path_2 = os.path.join(base_folder_2, scene) # Corresponding scene in the second base folder |
10 |
| - |
11 |
| - if not os.path.isdir(scene_path_1) or not os.path.isdir(scene_path_2): |
| 7 | + for scene in os.listdir(in_folder): |
| 8 | + scene_path_in = os.path.join(in_folder, scene) |
| 9 | + scene_path_out = os.path.join(out_folder, scene) # Corresponding scene in the second base folder |
| 10 | + print(f"Processing scene: {scene_path_in} -> {scene_path_out}") |
| 11 | + if not os.path.isdir(scene_path_in) or not os.path.isdir(scene_path_out): |
12 | 12 | continue
|
| 13 | + annotation_file_in = os.path.join(scene_path_in, "annotation_3d.json") |
| 14 | + annotation_file_out = os.path.join(scene_path_out, "annotation_3d.json") |
| 15 | + # print(f"Annotation file in: {annotation_file_in}, Annotation file out: {annotation_file_out}") |
| 16 | + shutil.move(annotation_file_in, annotation_file_out) |
| 17 | + print(f"Moved {annotation_file_in} to {annotation_file_out}") |
13 | 18 |
|
14 |
| - rendering_path_1 = os.path.join(scene_path_1, "2D_rendering") |
15 |
| - rendering_path_2 = os.path.join(scene_path_2, "2D_rendering") |
16 |
| - |
17 |
| - if not os.path.exists(rendering_path_1) or not os.path.exists(rendering_path_2): |
| 19 | + rendering_path_in = os.path.join(scene_path_in, "2D_rendering") |
| 20 | + rendering_path_out = os.path.join(scene_path_out, "2D_rendering") |
| 21 | + print(f"Rendering path in: {rendering_path_in}, Rendering path out: {rendering_path_out}") |
| 22 | + if not os.path.exists(rendering_path_in) or not os.path.exists(rendering_path_out): |
18 | 23 | continue
|
19 | 24 |
|
20 | 25 | # Iterate through render IDs
|
21 |
| - for render_id in os.listdir(rendering_path_1): |
22 |
| - render_path_1 = os.path.join(rendering_path_1, render_id) |
23 |
| - render_path_2 = os.path.join(rendering_path_2, render_id) |
| 26 | + for render_id in os.listdir(rendering_path_in): |
| 27 | + print("hello") |
| 28 | + render_path_in = os.path.join(rendering_path_in, render_id) |
| 29 | + render_path_out = os.path.join(rendering_path_out, render_id) |
24 | 30 |
|
25 |
| - perspective_path_1 = os.path.join(render_path_1, "perspective", "full") |
26 |
| - perspective_path_2 = os.path.join(render_path_2, "perspective", "full") |
| 31 | + perspective_path_in = os.path.join(render_path_in, "perspective", "full") |
| 32 | + perspective_path_out = os.path.join(render_path_out, "perspective", "full") |
| 33 | + print(f"Perspective path in: {perspective_path_in}, Perspective path out: {perspective_path_out}") |
27 | 34 |
|
28 |
| - if not os.path.exists(perspective_path_1) or not os.path.exists(perspective_path_2): |
| 35 | + if not os.path.exists(perspective_path_in) or not os.path.exists(perspective_path_out): |
29 | 36 | continue
|
30 |
| - |
| 37 | + print(f"Processing render ID: {render_id} -> {render_path_in} -> {render_path_out}") |
31 | 38 | # Iterate through views in the perspective folder
|
32 |
| - for view in os.listdir(perspective_path_1): |
33 |
| - view_path_1 = os.path.join(perspective_path_1, view) |
34 |
| - view_path_2 = os.path.join(perspective_path_2, view) |
| 39 | + for view in os.listdir(perspective_path_in): |
| 40 | + view_path_in = os.path.join(perspective_path_in, view) |
| 41 | + view_path_out = os.path.join(perspective_path_out, view) |
| 42 | + print(f"Processing view: {view_path_in} -> {view_path_out}") |
35 | 43 |
|
36 |
| - if not os.path.isdir(view_path_1) or not os.path.isdir(view_path_2): |
| 44 | + if not os.path.isdir(view_path_in) or not os.path.isdir(view_path_out): |
37 | 45 | continue
|
38 | 46 |
|
39 | 47 | # Check if instance.png exists in the target perspective folder
|
40 |
| - instance_file = os.path.join(view_path_2, "instance.png") |
| 48 | + instance_file = os.path.join(view_path_out, "instance.png") |
41 | 49 | if not os.path.exists(instance_file):
|
42 |
| - print(f"No instance.png found in {view_path_2}. Skipping.") |
| 50 | + print(f"No instance.png found in {view_path_out}. Skipping.") |
43 | 51 | continue
|
44 | 52 |
|
45 | 53 | # Move all files from the source folder to the target folder
|
46 |
| - for file_name in os.listdir(view_path_1): |
47 |
| - source_file = os.path.join(view_path_1, file_name) |
48 |
| - target_file = os.path.join(view_path_2, file_name) |
| 54 | + for file_name in os.listdir(view_path_in): |
| 55 | + source_file = os.path.join(view_path_in, file_name) |
| 56 | + target_file = os.path.join(view_path_out, file_name) |
49 | 57 |
|
50 | 58 | if os.path.isfile(source_file):
|
51 | 59 | print(f"Moving {source_file} to {target_file}")
|
52 | 60 | shutil.move(source_file, target_file)
|
53 | 61 |
|
54 | 62 | # Optionally: Remove the now-empty view folder
|
55 |
| - if not os.listdir(view_path_1): |
56 |
| - print(f"Removing empty folder: {view_path_1}") |
57 |
| - os.rmdir(view_path_1) |
| 63 | + if not os.listdir(view_path_in): |
| 64 | + print(f"Removing empty folder: {view_path_in}") |
| 65 | + os.rmdir(view_path_in) |
58 | 66 | count += 1
|
59 | 67 | print(f"Processed {count} scenes.")
|
60 | 68 |
|
61 | 69 | if __name__ == "__main__":
|
62 |
| - DIR_PREFIX='/Users/gauravpradeep/CrossOver_ScaleUp/' |
63 |
| - base_folder_2 = DIR_PREFIX+"Structured3D" # Directory with perspective instance.png |
64 |
| - # base_folder_1 = "Structured3D-1" # Directory with albedo.png, etc. |
65 |
| - |
66 |
| - for folder in ["Structured3D-1", "Structured3D-2", "Structured3D-3", "Structured3D-4", "Structured3D-5", "Structured3D-6", "Structured3D-7", "Structured3D-8", "Structured3D-9", "Structured3D-11", "Structured3D-12", "Structured3D-13", "Structured3D-14", "Structured3D-15", "Structured3D-16", "Structured3D-17", "Structured3D-18"]: |
67 |
| - base_folder_1 = DIR_PREFIX+folder |
68 |
| - combine_files(base_folder_1, base_folder_2) |
| 70 | + EXTRACTED_DIR='/Users/gauravpradeep/CrossOver_ScaleUp/extracted' |
| 71 | + out_dir = osp.join(EXTRACTED_DIR,"Structured3D_bbox/Structured3D") # this dir is the one that has perspective instance.png and bbox3d.json |
| 72 | + print(out_dir) |
| 73 | + for folder in os.listdir(EXTRACTED_DIR): |
| 74 | + if folder == 'Structured3D_bbox': |
| 75 | + continue |
| 76 | + in_folder = osp.join(EXTRACTED_DIR, folder, "Structured3D") |
| 77 | + print(f"Processing folder: {in_folder}") |
| 78 | + combine_files(in_folder, out_dir) |
69 | 79 |
|
0 commit comments