Sebastian Cavada commited on
Commit
7de9793
·
1 Parent(s): 3a1eecd

new things

Browse files
Files changed (5) hide show
  1. .gitignore +9 -0
  2. README.md +17 -14
  3. install.sh +4 -2
  4. prepare_data.py +35 -9
  5. run_core.sh +2 -5
.gitignore ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # folders
2
+ /images/*
3
+ /global/*
4
+
5
+ # files
6
+ cross_pairs_exhaustive.py
7
+ make_pairs_exhaustive.py
8
+ make_pairs_sequentially.py
9
+ report.py
README.md CHANGED
@@ -91,30 +91,33 @@ pip install nerfstudio
91
  COLMAP install
92
 
93
  ```bash
94
- conda install conda-forge::colmap
95
  ```
96
 
 
97
 
98
- ## Reproduce results
99
-
100
- ### 1. Download the files
101
 
102
- Once you downlaoded this repository you should be ready to go, you just need to unzip the folders
103
 
104
- ### 2. Process individual videos sequences
 
 
105
 
106
- bash
107
- python prepare_data.py
108
 
 
109
 
 
 
 
110
 
111
- ### 3. Reconstruct the campus hierarchically
112
 
113
- first run the core.sh script. This will reconstruct a base structure, upon which all the other reconstructions will be added to.
114
  This is the most important one.
115
 
116
-
117
  For the other scenes, for now just copy the run_template.sh file and modify according to the current scane name and file.
118
- Usually I run line by line to make sure everything is correct, but theoretically you could just run the entire file.
119
-
120
- TESTING LFS
 
91
  COLMAP install
92
 
93
  ```bash
94
+ conda install -y conda-forge::colmap
95
  ```
96
 
97
+ GLOMAP install
98
 
99
+ ```bash
100
+ conda install -y conda-forge::glomap
101
+ ```
102
 
103
+ ffmpeg for processing images
104
 
105
+ ```bash
106
+ conda install conda-forge::ffmpeg
107
+ ```
108
 
109
+ ## Reproduce results
 
110
 
111
+ ### 1. Pre-Process individual videos sequences
112
 
113
+ ```bash
114
+ python prepare_data.py
115
+ ```
116
 
117
+ ### 2. Reconstruct the campus hierarchically
118
 
119
+ first run the `run_core.sh` script. This will reconstruct a base structure, upon which all the other reconstructions will be added to.
120
  This is the most important one.
121
 
 
122
  For the other scenes, for now just copy the run_template.sh file and modify according to the current scane name and file.
123
+ Usually I run line by line to make sure everything is correct, but theoretically you could just run the entire file.
 
 
install.sh CHANGED
@@ -8,6 +8,8 @@ pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindi
8
 
9
  pip install nerfstudio
10
 
11
- conda install conda-forge::colmap
12
 
13
- conda install conda-forge::glomap
 
 
 
8
 
9
  pip install nerfstudio
10
 
11
+ conda install -y conda-forge::colmap
12
 
13
+ conda install -y conda-forge::glomap
14
+
15
+ conda install conda-forge::ffmpeg
prepare_data.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import itertools
3
  import subprocess
4
 
@@ -160,8 +161,7 @@ def generate_multi_camera_pairs(camera_images, window_size=20):
160
  # Pad shorter camera lists with None to match the longest list
161
  for camera, images in camera_images.items():
162
  if len(images) < max_images:
163
- camera_images[camera] = images + [None] * (max_images - len(images))
164
- print(camera_images)
165
 
166
  image_pairs = []
167
 
@@ -234,6 +234,16 @@ def count_images(output_directory):
234
  if os.path.isfile(os.path.join(output_directory, f)) and os.path.splitext(f)[1].lower() in image_extensions
235
  ])
236
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  def generate_images(out_dir, scene_name, config):
239
 
@@ -272,20 +282,36 @@ def generate_images(out_dir, scene_name, config):
272
 
273
  # Create output images directory if it doesn't exist
274
  output_images_dir = f"{out_dir}/{scene_name}/cam{folder_name}"
275
- os.makedirs(output_images_dir, exist_ok=True)
276
-
277
- skip_n_frames = config[scene_name]['skip_start_frames']
 
 
 
278
 
279
  # Construct the ffmpeg command
 
 
 
 
 
 
 
 
 
 
 
 
280
  ffmpeg_command = [
281
  "ffmpeg",
282
  "-hwaccel", "auto",
283
- "-ss", f"{skip_n_frames/2}", # Skip n frames at 2fps (n/2 seconds)
284
  "-i", video_file,
 
285
  "-vf", "fps=2,scale=iw:ih",
286
  "-q:v", "2",
287
  "-start_number", f"{prev_max_id}",
288
- f"{output_images_dir}/%06d_{camera_correspondances[folder_name]}.jpg"
289
  ]
290
 
291
  print(f"Running ffmpeg command for folder: {folder_name}")
@@ -326,7 +352,6 @@ def generate_sequential_pairs(folder_path, output_file_pairs_sequential, scene_n
326
  # Generate exhaustive list of pairs of images
327
  print(f"Generating image pairs for scene: {scene_name}")
328
  images_pairs_sequential = generate_multi_camera_pairs(camera_images)
329
- print(images_pairs_sequential)
330
 
331
  # Save pairs to file
332
  save_pairs_to_file(images_pairs_sequential, output_file_pairs_sequential, scene)
@@ -406,7 +431,8 @@ def process_scene(scene_name, config, out_dir="./images"):
406
  # Scene configurations
407
  config = {
408
  "campus_core": {
409
- 'skip_start_frames': 0,
 
410
  'src_scene': "campus_core",
411
  'src_cam': "core01",
412
  'target_scene': "mid_library",
 
1
  import os
2
+ import json
3
  import itertools
4
  import subprocess
5
 
 
161
  # Pad shorter camera lists with None to match the longest list
162
  for camera, images in camera_images.items():
163
  if len(images) < max_images:
164
+ camera_images[camera] = images + [None] * (max_images - len(images))
 
165
 
166
  image_pairs = []
167
 
 
234
  if os.path.isfile(os.path.join(output_directory, f)) and os.path.splitext(f)[1].lower() in image_extensions
235
  ])
236
 
237
+ def get_video_duration(video_path):
238
+ result = subprocess.run([
239
+ "ffprobe", "-v", "error",
240
+ "-show_entries", "format=duration",
241
+ "-of", "json", video_path
242
+ ], stdout=subprocess.PIPE)
243
+ duration = float(json.loads(result.stdout)["format"]["duration"])
244
+ return duration
245
+
246
+
247
 
248
  def generate_images(out_dir, scene_name, config):
249
 
 
282
 
283
  # Create output images directory if it doesn't exist
284
  output_images_dir = f"{out_dir}/{scene_name}/cam{folder_name}"
285
+ os.makedirs(output_images_dir, exist_ok=True)
286
+
287
+ duration = get_video_duration(video_file)
288
+ skip_start = config[scene_name].get('skip_start_seconds', 0)
289
+ skip_end = config[scene_name].get('skip_end_seconds', 0)
290
+ duration_to_keep = duration - skip_start - skip_end
291
 
292
  # Construct the ffmpeg command
293
+ # ffmpeg_command = [
294
+ # "ffmpeg",
295
+ # "-hwaccel", "auto",
296
+ # "-ss", f"{skip_start_seconds}", # Skip n frames at 2fps (n/2 seconds)
297
+ # "-i", video_file,
298
+ # "-vf", "fps=2,scale=iw:ih",
299
+ # "-q:v", "2",
300
+ # "-start_number", f"{prev_max_id}",
301
+ # f"{output_images_dir}/%06d_{camera_correspondances[folder_name]}.jpg"
302
+ # ]
303
+
304
+ # Build ffmpeg command
305
  ffmpeg_command = [
306
  "ffmpeg",
307
  "-hwaccel", "auto",
308
+ "-ss", f"{skip_start}",
309
  "-i", video_file,
310
+ "-t", f"{duration_to_keep}",
311
  "-vf", "fps=2,scale=iw:ih",
312
  "-q:v", "2",
313
  "-start_number", f"{prev_max_id}",
314
+ f"{output_images_dir}/%06d{camera_correspondances[folder_name]}.jpg"
315
  ]
316
 
317
  print(f"Running ffmpeg command for folder: {folder_name}")
 
352
  # Generate exhaustive list of pairs of images
353
  print(f"Generating image pairs for scene: {scene_name}")
354
  images_pairs_sequential = generate_multi_camera_pairs(camera_images)
 
355
 
356
  # Save pairs to file
357
  save_pairs_to_file(images_pairs_sequential, output_file_pairs_sequential, scene)
 
431
  # Scene configurations
432
  config = {
433
  "campus_core": {
434
+ 'skip_start_seconds': 5,
435
+ 'skip_end_seconds': 20,
436
  'src_scene': "campus_core",
437
  'src_cam': "core01",
438
  'target_scene': "mid_library",
run_core.sh CHANGED
@@ -11,10 +11,7 @@ echo "Running feature matching..."
11
  colmap matches_importer --database_path ./global/database_core.db --match_list_path ./images/campus_core/image_pairs_exhaustive.txt
12
 
13
  echo "Reconstructing 3D model..."
14
- glomap mapper --database_path ./global/database_core.db --image_path ./images --output_path ./campus_core
15
-
16
- ENDIN=$(date +"%H:%M:%S")
17
- curl -X POST -H 'Content-Type: application/json' -d "{\"chat_id\": \"777722458\", \"text\": \"FINE COLMAP\", \"disable_notification\": true}" https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage
18
 
19
  echo "Showing result"
20
- colmap gui --import_path ./campus_core/0 --database_path ./global/database_core.db --image_path ./images
 
11
  colmap matches_importer --database_path ./global/database_core.db --match_list_path ./images/campus_core/image_pairs_exhaustive.txt
12
 
13
  echo "Reconstructing 3D model..."
14
+ colmap mapper --database_path ./global/database_core.db --image_path ./images --output_path ./global/campus_core --image_list_path ./images/campus_core/image_list.txt
 
 
 
15
 
16
  echo "Showing result"
17
+ colmap gui --import_path ./global/campus_core/0 --database_path ./global/database_core.db --image_path ./images