Skip to content

Commit 4a626d1

Browse files
authored
Merge pull request #56 from bit-bots/feature/simulation-image-conversion
feat(import): correctly handle simulation imports
2 parents 0f88b44 + 584c308 commit 4a626d1

File tree

4 files changed

+223
-276
lines changed

4 files changed

+223
-276
lines changed

ddlitlab2024/dataset/cli/run.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,20 @@ def main():
6161
from ddlitlab2024.dataset.imports.strategies.bitbots import BitBotsImportStrategy
6262

6363
logger.info(f"Trying to import file '{args.file}' to database...")
64+
65+
simulated = False
66+
location = "RoboCup2024"
67+
68+
if "simulation" in str(args.file) or "simulated" in str(args.file):
69+
simulated = True
70+
location = "Webots Simulator"
71+
6472
metadata = ImportMetadata(
6573
allow_public=True,
6674
team_name="Bit-Bots",
6775
robot_type="Wolfgang-OP",
68-
location="RoboCup2024",
69-
simulated=False,
76+
location=location,
77+
simulated=simulated,
7078
)
7179
image_converter = ImageConverter(MaxRateResampler(IMAGE_MAX_RESAMPLE_RATE_HZ))
7280
game_state_converter = GameStateConverter(OriginalRateResampler())

ddlitlab2024/dataset/converters/image_converter.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def convert_to_model(self, data: InputData, relative_timestamp: float, recording
3737
return models
3838

3939
def _create_image(self, data, sampling_timestamp: float, recording: Recording) -> Image:
40-
img_array = np.frombuffer(data.data, np.uint8).reshape((data.height, data.width, 3))
40+
img_array = np.frombuffer(data.data, np.uint8).reshape((data.height, data.width, -1))
4141

4242
will_img_be_upscaled = recording.img_width_scaling > 1.0 or recording.img_height_scaling > 1.0
4343
interpolation = cv2.INTER_AREA
@@ -50,9 +50,17 @@ def _create_image(self, data, sampling_timestamp: float, recording: Recording) -
5050
resized_rgb_img = resized_img
5151
case "bgr8":
5252
resized_rgb_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2RGB)
53+
case "bgra8":
54+
resized_rgb_img = cv2.cvtColor(resized_img, cv2.COLOR_BGRA2RGB)
5355
case _:
5456
raise AssertionError(f"Unsupported image encoding: {data.encoding}")
5557

58+
assert resized_rgb_img.shape == (
59+
recording.img_height,
60+
recording.img_width,
61+
3,
62+
), "Converted image does not have the expected dimensions"
63+
5664
return Image(
5765
stamp=sampling_timestamp,
5866
recording=recording,

0 commit comments

Comments
 (0)