Skip to content

Commit

Permalink
feat: implement Scene.from_json() for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 13, 2024
1 parent 68b463c commit f63f2ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions raillabel/format/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from raillabel.json_format import (
JSONCoordinateSystem,
JSONObject,
JSONScene,
JSONStreamCamera,
JSONStreamOther,
Expand Down Expand Up @@ -46,6 +47,7 @@ def from_json(cls, json: JSONScene) -> Scene:
return Scene(
metadata=Metadata.from_json(json.openlabel.metadata),
sensors=_sensors_from_json(json.openlabel.streams, json.openlabel.coordinate_systems),
objects=_objects_from_json(json.openlabel.objects),
)


Expand Down Expand Up @@ -77,3 +79,10 @@ def _sensors_from_json(
sensors[sensor_id] = OtherSensor.from_json(json_stream, json_coordinate_system)

return sensors


def _objects_from_json(json_objects: dict[UUID, JSONObject] | None) -> dict[UUID, Object]:
if json_objects is None:
return {}

return {obj_uid: Object.from_json(json_obj) for obj_uid, json_obj in json_objects.items()}
23 changes: 22 additions & 1 deletion tests/test_raillabel/format/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@


@pytest.fixture
def scene_json(metadata_json, camera_json, lidar_json, radar_json) -> JSONScene:
def scene_json(
metadata_json,
camera_json,
lidar_json,
radar_json,
object_person_uid,
object_person_json,
object_track_uid,
object_track_json,
) -> JSONScene:
return JSONScene(
openlabel=JSONSceneContent(
metadata=metadata_json,
Expand All @@ -32,6 +41,10 @@ def scene_json(metadata_json, camera_json, lidar_json, radar_json) -> JSONScene:
"lidar": lidar_json[0],
"radar": radar_json[0],
},
objects={
object_person_uid: object_person_json,
object_track_uid: object_track_json,
},
)
)

Expand All @@ -42,6 +55,10 @@ def scene(
camera,
lidar,
radar,
object_person_uid,
object_person,
object_track_uid,
object_track,
) -> Scene:
return Scene(
metadata=metadata,
Expand All @@ -50,6 +67,10 @@ def scene(
"lidar": lidar,
"radar": radar,
},
objects={
object_person_uid: object_person,
object_track_uid: object_track,
},
)


Expand Down

0 comments on commit f63f2ba

Please sign in to comment.