Sebastian Cavada
commited on
Commit
·
2ffcc4f
1
Parent(s):
34f6878
adding seuqential same_camera as well maybe bug or not
Browse files- prepare_data.py +27 -3
prepare_data.py
CHANGED
@@ -148,6 +148,8 @@ def generate_cross_camera_pairs(images_list1, images_list2):
|
|
148 |
def generate_multi_camera_pairs(camera_images, window_size=20):
|
149 |
"""
|
150 |
Generate image pairs across multiple cameras sequentially.
|
|
|
|
|
151 |
:param camera_images: Dictionary of camera names to image lists
|
152 |
:param window_size: Number of images to match before and after each image
|
153 |
:return: List of image pair tuples with camera names
|
@@ -159,6 +161,7 @@ def generate_multi_camera_pairs(camera_images, window_size=20):
|
|
159 |
for camera, images in camera_images.items():
|
160 |
if len(images) < max_images:
|
161 |
camera_images[camera] = images + [None] * (max_images - len(images))
|
|
|
162 |
|
163 |
image_pairs = []
|
164 |
|
@@ -170,16 +173,35 @@ def generate_multi_camera_pairs(camera_images, window_size=20):
|
|
170 |
if base_images[current_index] is None:
|
171 |
continue
|
172 |
|
173 |
-
# Generate pairs with
|
174 |
for target_camera, target_images in camera_images.items():
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
continue
|
177 |
|
178 |
# Skip if target image is None
|
179 |
if target_images[current_index] is None:
|
180 |
continue
|
181 |
|
182 |
-
# Add current image pair
|
183 |
image_pairs.append((f"{base_camera}/{base_images[current_index]}",
|
184 |
f"{target_camera}/{target_images[current_index]}"))
|
185 |
|
@@ -299,10 +321,12 @@ def generate_exhaustive_pairs(folder_path, output_file_pairs_exhaustive, scene_n
|
|
299 |
def generate_sequential_pairs(folder_path, output_file_pairs_sequential, scene_name):
|
300 |
# Get images from all cameras
|
301 |
camera_images = get_list_images(folder_path)
|
|
|
302 |
|
303 |
# Generate exhaustive list of pairs of images
|
304 |
print(f"Generating image pairs for scene: {scene_name}")
|
305 |
images_pairs_sequential = generate_multi_camera_pairs(camera_images)
|
|
|
306 |
|
307 |
# Save pairs to file
|
308 |
save_pairs_to_file(images_pairs_sequential, output_file_pairs_sequential, scene)
|
|
|
148 |
def generate_multi_camera_pairs(camera_images, window_size=20):
|
149 |
"""
|
150 |
Generate image pairs across multiple cameras sequentially.
|
151 |
+
Also generates pairs within the same camera if only one camera is present.
|
152 |
+
|
153 |
:param camera_images: Dictionary of camera names to image lists
|
154 |
:param window_size: Number of images to match before and after each image
|
155 |
:return: List of image pair tuples with camera names
|
|
|
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 |
|
|
|
173 |
if base_images[current_index] is None:
|
174 |
continue
|
175 |
|
176 |
+
# Generate pairs with other cameras
|
177 |
for target_camera, target_images in camera_images.items():
|
178 |
+
# Skip self-pairing at the same index (would create identical pairs)
|
179 |
+
if base_camera == target_camera and current_index == current_index:
|
180 |
+
# But still generate pairs for same camera at different timestamps
|
181 |
+
# if there's only one camera
|
182 |
+
if len(camera_images) == 1:
|
183 |
+
# Generate pairs within window size for forward and backward directions
|
184 |
+
for i in range(1, window_size + 1):
|
185 |
+
# Forward window
|
186 |
+
if current_index + i < max_images and base_images[current_index + i] is not None:
|
187 |
+
image_pairs.append((
|
188 |
+
f"{base_camera}/{base_images[current_index]}",
|
189 |
+
f"{base_camera}/{base_images[current_index + i]}"
|
190 |
+
))
|
191 |
+
|
192 |
+
# Backward window
|
193 |
+
if current_index - i >= 0 and base_images[current_index - i] is not None:
|
194 |
+
image_pairs.append((
|
195 |
+
f"{base_camera}/{base_images[current_index]}",
|
196 |
+
f"{base_camera}/{base_images[current_index - i]}"
|
197 |
+
))
|
198 |
continue
|
199 |
|
200 |
# Skip if target image is None
|
201 |
if target_images[current_index] is None:
|
202 |
continue
|
203 |
|
204 |
+
# Add current image pair (from different cameras)
|
205 |
image_pairs.append((f"{base_camera}/{base_images[current_index]}",
|
206 |
f"{target_camera}/{target_images[current_index]}"))
|
207 |
|
|
|
321 |
def generate_sequential_pairs(folder_path, output_file_pairs_sequential, scene_name):
|
322 |
# Get images from all cameras
|
323 |
camera_images = get_list_images(folder_path)
|
324 |
+
print(camera_images)
|
325 |
|
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)
|