Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(import): correctly handle simulation imports #56

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ddlitlab2024/dataset/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ def main():
from ddlitlab2024.dataset.imports.strategies.bitbots import BitBotsImportStrategy

logger.info(f"Trying to import file '{args.file}' to database...")

simulated = False
location = "RoboCup2024"

if "simulation" in str(args.file) or "simulated" in str(args.file):
simulated = True
location = "Webots Simulator"

metadata = ImportMetadata(
allow_public=True,
team_name="Bit-Bots",
robot_type="Wolfgang-OP",
location="RoboCup2024",
simulated=False,
location=location,
simulated=simulated,
)
image_converter = ImageConverter(MaxRateResampler(IMAGE_MAX_RESAMPLE_RATE_HZ))
game_state_converter = GameStateConverter(OriginalRateResampler())
Expand Down
10 changes: 9 additions & 1 deletion ddlitlab2024/dataset/converters/image_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def convert_to_model(self, data: InputData, relative_timestamp: float, recording
return models

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

will_img_be_upscaled = recording.img_width_scaling > 1.0 or recording.img_height_scaling > 1.0
interpolation = cv2.INTER_AREA
Expand All @@ -50,9 +50,17 @@ def _create_image(self, data, sampling_timestamp: float, recording: Recording) -
resized_rgb_img = resized_img
case "bgr8":
resized_rgb_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2RGB)
case "bgra8":
resized_rgb_img = cv2.cvtColor(resized_img, cv2.COLOR_BGRA2RGB)
case _:
raise AssertionError(f"Unsupported image encoding: {data.encoding}")

assert resized_rgb_img.shape == (
recording.img_height,
recording.img_width,
3,
), "Converted image does not have the expected dimensions"

return Image(
stamp=sampling_timestamp,
recording=recording,
Expand Down
Loading
Loading