bikeped.sim¶
The CARLA renderer. Modules that talk to the simulator import carla only when first used, so everything below imports without it. CARLA rendering explains how the parts fit together.
types
¶
Data types shared by the CARLA runtime and the imaging code.
Nothing in this module imports carla. The runtime (session, actors, rigs,
runner) fills these records from the simulator, and the imaging code
(projection, ground truth, overlay, recorder, export) consumes them, so both
halves can be developed and tested without a server.
Frames of reference¶
Scenario frame
The frame of the testbench scenarios: metres, right-handed, x along the
road (cyclists travel along it), y across the road (pedestrians cross
along it), crosswalk centre at (5, 0).
World frame
The CARLA world frame: metres, left-handed, x forward, y right,
z up. Rotations are (pitch, yaw, roll) in degrees with the Unreal
convention used by carla.Rotation.
Camera basis
A camera is described by its position and by three orthonormal world-frame
vectors forward, right and up. A world point P has camera
coordinates (f, r, u) = (forward . d, right . d, up . d) with
d = P - position. Image u grows with r and image v grows
with -u.
CameraModel
dataclass
¶
CameraModel(
name: str,
kind: str,
width: int,
height: int,
position: Vec3,
forward: Vec3,
right: Vec3,
up: Vec3,
fov_deg: float = 90.0,
cx: Optional[float] = None,
cy: Optional[float] = None,
f_px_per_rad: Optional[float] = None,
k1: float = 0.0,
k2: float = 0.0,
circle_radius_px: Optional[float] = None,
)
Intrinsics and world pose of one rendered view.
kind is "pinhole" or "fisheye".
Pinhole: fov_deg is the horizontal field of view, and the focal length
in pixels is width / (2 tan(fov / 2)).
Fisheye: the optical axis is forward and the projection is the
equidistant model with odd polynomial terms,
r = f_px_per_rad * (theta + k1 theta^3 + k2 theta^5), where theta
is the angle between the ray and the optical axis. fov_deg is the full
field of view of the image circle and circle_radius_px its radius.
cx and cy default to the image centre.
AgentState
dataclass
¶
AgentState(
id: int,
kind: str,
sx: float,
sy: float,
heading: float,
speed: float,
location: Vec3,
rotation: Vec3,
extent: Vec3,
role: str = "scripted",
model: str = "",
blueprint: str = "",
track_error_m: float = 0.0,
instance_id: Optional[int] = None,
)
One agent at one frame.
sx, sy and heading are the scripted pose in the scenario frame
and are what the decision pipeline and the ground-truth danger model see.
location, rotation and extent describe the oriented 3D box of
the simulated actor in the world frame: location is the box centre,
extent the half sizes along the actor's forward, right and up axes.
track_error_m is the ground-plane distance between the scripted and the
simulated position.
FrameRecord
dataclass
¶
FrameRecord(
index: int,
t: float,
agents: List[AgentState],
state: str = "idle",
states: Dict[str, str] = dict(),
alert_pair: Optional[Tuple[int, int]] = None,
danger: Optional[Dict[str, Any]] = None,
cameras: Dict[str, CameraModel] = dict(),
images: Dict[str, ndarray] = dict(),
aux: Dict[str, ndarray] = dict(),
)
Everything known about one simulation step.
images maps a view name to a BGR uint8 array. aux holds
optional per-view buffers under "<view>/depth" (float32 metres) and
"<view>/instance" (integer ids). Neither is serialised to the manifest.
RunInfo
dataclass
¶
RunInfo(
scenario_name: str,
scenario_id: str,
suite: str = "conformance",
fps: int = 30,
duration_s: float = 0.0,
engine: str = "ue4",
server_version: str = "",
client_version: str = "",
map: str = "",
crosswalk_id: Optional[int] = None,
weather: str = "clear_noon",
quality: str = "standard",
drive: str = "velocity",
ambient: str = "none",
seed: int = 0,
views: List[str] = list(),
site: Dict[str, Any] = dict(),
pipeline_config: str = "default",
extra: Dict[str, Any] = dict(),
)
Metadata of one rendered scenario, written at the top of the manifest.
engine
¶
Engine profiles, server detection and capability probing.
Two CARLA generations are supported: CARLA 0.9.14 to 0.9.16 on Unreal Engine 4
(ue4) and CARLA 0.10.0 on Unreal Engine 5 (ue5). The rest of the package
asks :func:probe what a server offers instead of branching on version numbers,
so a feature missing from one build degrades the same way on any engine.
carla is imported lazily through :func:carla_module. Tests replace it with
:func:set_carla_module.
EngineProfile
dataclass
¶
EngineProfile(
name: str,
launcher: str,
default_map: str,
default_drive: str,
default_port: int,
launch_flags: Tuple[str, ...],
supports_quality_flag: bool,
root_env: str,
wheel_hint: str,
search_paths: Tuple[str, ...] = (),
)
Static facts about one CARLA generation.
Capabilities
dataclass
¶
Capabilities(
engine: str,
server_version: str,
client_version: str,
map: str,
maps: List[str] = list(),
two_wheelers: List[str] = list(),
bicycles: List[str] = list(),
walkers: int = 0,
wheelchair_walkers: List[str] = list(),
child_walkers: List[str] = list(),
vehicles: int = 0,
depth_camera: bool = False,
instance_camera: bool = False,
ground_projection: bool = False,
light_manager: bool = False,
crosswalks: int = 0,
)
What one running server offers to the renderer.
set_carla_module
¶
carla_module
¶
Return the carla module, importing it on first use.
Raises ImportError with installation hints when the client is missing.
Source code in bikeped/sim/engine.py
engine_for_version
¶
Map a CARLA version string to ue4 (0.9.x) or ue5 (0.10.x and later).
Source code in bikeped/sim/engine.py
detect_engine
¶
Return ue4 or ue5 for the connected server and warn on a client mismatch.
Source code in bikeped/sim/engine.py
attribute_text
¶
Value of a blueprint attribute as lower-case text, or None when absent.
The real client refuses as_str() on numeric attributes, so the typed
accessors are tried in turn.
Source code in bikeped/sim/engine.py
is_two_wheeler
¶
True for bicycles, scooters and motorcycles in any CARLA build.
Source code in bikeped/sim/engine.py
probe
¶
Query a connected server for maps, blueprints, sensors and world features.
Source code in bikeped/sim/engine.py
format_capabilities
¶
Render capabilities as an aligned two-column table.
Source code in bikeped/sim/engine.py
root_from_env
¶
server
¶
Locate, launch and stop a CARLA server process.
A CARLA release ships a launcher script (CarlaUE4.sh in the Unreal
Engine 4 releases, CarlaUnreal.sh in the Unreal Engine 5 release) that
starts the simulator binary. This module finds an install, builds the launch
command for either engine, runs it in its own process group, waits until a
client can read the server version and stops the whole group again.
carla is only needed by :meth:ServerProcess.wait_ready, which asks the
server for its version through a client.
ServerProcess
¶
ServerProcess(
engine: str,
root: Optional[PathLike] = None,
port: int = 2000,
quality: str = "Epic",
windowed: bool = False,
host: str = "127.0.0.1",
log_path: Optional[PathLike] = None,
extra_args: Sequence[str] = (),
)
One CARLA server started from a local install.
The launcher script starts the simulator binary as a child process, so the
server gets its own session and process group and :meth:stop signals the
whole group. A terminal interrupt therefore reaches only the Python
process, which is expected to call :meth:stop on its way out
(:func:managed_server does).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
str
|
|
required |
root
|
Optional[PathLike]
|
install folder; looked up with :func: |
None
|
port
|
int
|
RPC port of the server. |
2000
|
quality
|
str
|
UE4 quality level, |
'Epic'
|
windowed
|
bool
|
open a window instead of rendering off screen. |
False
|
host
|
str
|
address used to check that the server answers. |
'127.0.0.1'
|
log_path
|
Optional[PathLike]
|
file that receives the server's output; a file in the system temporary folder by default. |
None
|
extra_args
|
Sequence[str]
|
further launcher arguments, appended as they are. |
()
|
Source code in bikeped/sim/server.py
start
¶
Launch the server and return immediately.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
a server was already started from this object, or something already listens on the RPC port. |
FileNotFoundError
|
no install with the engine's launcher was found. |
Source code in bikeped/sim/server.py
wait_ready
¶
Block until a client can read the server version, and return it.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
the server was not started or exited while starting up. |
TimeoutError
|
the server did not answer within |
Source code in bikeped/sim/server.py
stop
¶
Stop the server and every process it started.
The process group receives SIGTERM and, if it is still alive after
grace seconds, SIGKILL. Calling this on a server that is not
running does nothing.
Source code in bikeped/sim/server.py
log_tail
¶
Last lines lines of the server's output, empty if unreadable.
Source code in bikeped/sim/server.py
launcher_path
¶
Path of the launcher script inside the install at root.
The UE4 archives keep the launcher at the top of the install and the UE5
archive keeps it under Linux/, so both places are checked. When the
script is in neither, the top-level path is returned so that callers can
name it in their error message.
Source code in bikeped/sim/server.py
find_install
¶
Return the root folder of a CARLA install for engine.
An explicit root is the only place searched when it is given. Without
it, the engine's environment variable (CARLA_UE4_ROOT or
CARLA_UE5_ROOT) is tried first and then the profile's list of common
install paths.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
no candidate contains the engine's launcher script. |
Source code in bikeped/sim/server.py
build_command
¶
build_command(
engine: str,
root: Optional[PathLike] = None,
port: int = 2000,
quality: str = "Epic",
windowed: bool = False,
extra_args: Sequence[str] = (),
) -> List[str]
Build the argument list that launches a server.
The server renders off screen unless windowed is set. port is the
RPC port; the server also uses the two ports after it for streaming.
quality is passed as -quality-level= on UE4 and ignored on UE5,
whose launcher has no such flag. With root left out the install is
looked up with :func:find_install.
Source code in bikeped/sim/server.py
managed_server
¶
managed_server(
engine: str,
root: Optional[PathLike] = None,
port: int = 2000,
quality: str = "Epic",
windowed: bool = False,
timeout: float = 180.0,
host: str = "127.0.0.1",
log_path: Optional[PathLike] = None,
) -> Iterator[ServerProcess]
Run a CARLA server for the duration of a with block.
The server is started, the block is entered once a client can reach it, and the server is stopped when the block exits for any reason, including an exception or a keyboard interrupt.
Source code in bikeped/sim/server.py
session
¶
Connection to a CARLA server in synchronous mode with guaranteed cleanup.
:class:Session connects (with retries), loads the requested map only when it
is not already loaded, switches the world and the Traffic Manager to
synchronous mode with a fixed time step, tracks every actor spawned through it
and, on exit (including KeyboardInterrupt), destroys those actors and
restores the previous world settings. :class:SensorHub returns, for each
world.tick(), the measurement of every sensor for exactly that frame.
SensorHub
¶
Frame-synchronised collection of sensor data.
Each registered sensor gets its own queue; :meth:collect blocks until
every sensor has delivered the measurement of the requested frame and
discards older ones.
Source code in bikeped/sim/session.py
collect
¶
Decoded data of every sensor for frame.
Source code in bikeped/sim/session.py
Session
¶
Session(
host: str = "127.0.0.1",
port: int = 2000,
*,
map_name: Optional[str] = None,
fixed_delta: float = 1.0 / 30.0,
seed: int = 0,
timeout: float = 30.0,
retries: int = 5,
tm_port: Optional[int] = None,
)
Synchronous-mode session on one CARLA server.
Use as a context manager. fixed_delta is the simulation step in seconds
(1 / fps). map_name is loaded only when the current map differs.
Source code in bikeped/sim/session.py
traffic_manager
¶
Traffic Manager in synchronous mode and seeded, or None when unavailable.
Source code in bikeped/sim/session.py
spawn
¶
Spawn and track an actor; raises RuntimeError when the server refuses.
Source code in bikeped/sim/session.py
try_spawn
¶
Like :meth:spawn but returns None on failure.
Source code in bikeped/sim/session.py
destroy
¶
Destroy one tracked actor now and stop tracking it.
close
¶
Stop sensors, destroy tracked actors, restore settings. Safe to call twice.
Source code in bikeped/sim/session.py
image_to_bgr
¶
carla.Image (BGRA bytes) to a contiguous uint8 BGR array.
depth_to_metres
¶
Decode a sensor.camera.depth image to float32 metres (1000 m far plane).
Source code in bikeped/sim/session.py
instance_ids
¶
Decode sensor.camera.instance_segmentation to int32 object ids (G + B * 256).
Source code in bikeped/sim/session.py
site
¶
Placement of the scenario frame on a CARLA crosswalk.
The scenario frame (see :mod:bikeped.sim.types) is anchored on one crosswalk:
scenario +y runs along the crosswalk (the direction pedestrians cross),
scenario +x runs along the road, and the crosswalk centre is scenario
(5, 0). As in the original carla_scenario.py, the reference short edge
of the crosswalk polygon defines -y (the pole stands there). The road axis
is the cross axis turned by (a, b) -> (-b, a) in world coordinates: the
world frame is left-handed, so this is the choice that keeps the scene
unmirrored (seen from above, turning from scenario +x to +y is a
counter-clockwise turn in both frames, and a cyclist approaching from scenario
+x enters the pole view from the right, as in the testbench camera).
Everything here is plain numpy. :meth:Site.from_world is the only method that
touches a CARLA world, and only through world.get_map().get_crosswalks().
Site
dataclass
¶
Site(
origin: Tuple[float, float],
road_axis: Tuple[float, float],
cross_axis: Tuple[float, float],
ground_z: float,
road_half_width: float,
crosswalk_id: Any = None,
pole_xy: Tuple[float, float] = (5.0, -13.0),
pole_height: float = POLE_HEIGHT_M,
)
A crosswalk with the scenario frame attached to it.
origin is the world (X, Y) of scenario (0, 0); road_axis and
cross_axis are the world unit vectors of scenario +x and +y.
ground_z is the world height of the crosswalk surface and
road_half_width half the crosswalk length (kerb to kerb), in metres.
pole_world
property
¶
World position of the pole camera (the testbench camera position).
from_crosswalk
classmethod
¶
Build a site from one crosswalks.json entry (corners, center).
Source code in bikeped/sim/site.py
from_json
classmethod
¶
Load entry index (list position or id) of a crosswalks.json file.
Source code in bikeped/sim/site.py
from_world
classmethod
¶
Build a site from crosswalk index of the loaded map.
Map.get_crosswalks() returns closed polygons as a flat list of
locations; rectangles come with their first point repeated (five points).
Source code in bikeped/sim/site.py
to_world
¶
Scenario (x, y) and height above ground to world (X, Y, Z).
Source code in bikeped/sim/site.py
to_scenario
¶
World (X, Y) to scenario (x, y).
Source code in bikeped/sim/site.py
heading_to_yaw
¶
Scenario heading (radians, 0 = +x) to CARLA yaw (degrees, clockwise from above).
Source code in bikeped/sim/site.py
yaw_to_heading
¶
Inverse of :meth:heading_to_yaw.
Source code in bikeped/sim/site.py
direction
¶
World-frame unit vector (X, Y, 0) of a scenario heading.
crosswalks_from_points
¶
Split CARLA's flat crosswalk point list into crosswalks.json-like entries.
A polygon ends where a point repeats the polygon's first point. Polygons with
other than four distinct corners are approximated by their minimum-area
rectangle so the edge logic of :meth:Site.from_crosswalk applies.
Source code in bikeped/sim/site.py
motion
¶
Smooth rendering poses for scripted scenario agents.
Positions come straight from the scripted piecewise-linear path with the same
semantics as decision_testbench.interpolate_agent, so the ground truth stays
exact. Only quantities that the testbench does not use are smoothed: the
heading (paths turn instantly at waypoints, people and bicycles do not) and the
lean of a two-wheeler, derived from speed and yaw rate. All angles are in the
scenario frame, radians, counter-clockwise from +x.
Pose
dataclass
¶
Pose(
t: float,
active: bool,
x: float,
y: float,
vx: float,
vy: float,
speed: float,
path_heading: float,
heading: float,
yaw_rate: float,
lean: float,
)
Pose of one agent at one instant (scenario frame).
Trajectory
¶
Trajectory(
agent: Dict[str, Any],
fps: int = 30,
time_constant: Optional[float] = None,
max_turn_rate: Optional[float] = None,
)
Rendering trajectory of one scenario agent sampled on a fixed time grid.
time_constant is the time constant (s) of the critically damped heading
filter and max_turn_rate its slew limit (rad/s). Headings are computed
once over the whole active window at fps so that :meth:sample is pure
and repeatable.
Source code in bikeped/sim/motion.py
active
¶
position
¶
Scripted position, clamped to the path ends outside the active window.
Source code in bikeped/sim/motion.py
velocity
¶
Velocity (m/s) of the segment containing t; zero outside the window.
Source code in bikeped/sim/motion.py
path_heading
¶
Heading of the segment containing t (what interpolate_agent reports).
Source code in bikeped/sim/motion.py
heading
¶
Smoothed heading (rad) and yaw rate (rad/s) at t.
Source code in bikeped/sim/motion.py
sample
¶
Full pose at time t.
Source code in bikeped/sim/motion.py
wrap_angle
¶
trajectories
¶
One :class:Trajectory per scenario agent, in scenario order.
scripted_agents
¶
Agents active at t exactly as interpolate_agent reports them.
Source code in bikeped/sim/motion.py
actors
¶
Spawning and driving the scripted scenario agents.
Each scenario agent becomes one CARLA actor (a walker for person agents, a
two-wheeled vehicle for bike agents, or a walker standing in for a cyclist
when the engine has no rideable two-wheeler and cyclist_proxy='walker').
Two drive modes are available:
kinematic
The actor is placed on the scripted pose every tick. Height comes from a
ground profile sampled with world.ground_projection before any actor
exists (so the ray never hits an agent), yaw from the smoothed heading and,
for two-wheelers, roll from the lean angle. Walkers keep physics and also
receive a WalkerControl so their walk cycle plays.
velocity
Walkers are steered with WalkerControl (scripted velocity plus a
proportional correction on position error) and riders with target linear
and angular velocities plus a light throttle and steer so wheels, pedals and
handlebar move. An actor is re-placed on its scripted pose only when the
position error exceeds a tolerance.
Positions reported to the decision pipeline and the ground truth always come from the script, never from the simulated actor.
Agent
dataclass
¶
Agent(
trajectory: Trajectory,
kind: str,
model: str,
actor: Any = None,
bp: Any = None,
blueprint: str = "",
walker: bool = True,
half_height: float = 0.9,
visible: bool = False,
ground: List[Tuple[float, float, float]] = list(),
)
One scripted agent and the actor that renders it.
Cast
¶
Cast(
session: Any,
site: Site,
scenario: Dict[str, Any],
trajectories: Sequence[Trajectory],
caps: Capabilities,
*,
drive: str = "kinematic",
seed: int = 0,
cyclist_proxy: Optional[str] = None,
walker_drive: Optional[str] = None,
)
All scripted actors of one scenario.
drive is the drive mode for riders and walkers (see module docstring).
cyclist_proxy is None or 'walker'.
Source code in bikeped/sim/actors.py
sample_ground
¶
Sample ground heights along every path before any agent is spawned.
Source code in bikeped/sim/actors.py
spawn
¶
Choose the blueprint of every agent; actors appear when their window starts.
Actors are spawned on their first active tick and destroyed after their last one. Parking inactive actors under the map is not an option: walkers keep falling with physics disabled and the engine deletes them at the kill height.
Source code in bikeped/sim/actors.py
drive_tick
¶
Command every actor for the step that ends at t.
Source code in bikeped/sim/actors.py
states
¶
AgentState of every agent active at t from the actual actor pose.
Source code in bikeped/sim/actors.py
choose_walker
¶
Pick a walker blueprint for a hint; returns (blueprint, use_wheelchair).
Source code in bikeped/sim/actors.py
choose_rider
¶
Pick a two-wheeler blueprint for a hint, or None when the engine has none.
Source code in bikeped/sim/actors.py
environment
¶
Weather and lighting presets.
Each preset is a plain dict of carla.WeatherParameters fields. Fields a
server does not know are skipped, so the same table serves CARLA 0.9.x and
0.10.0. The sun azimuth is not stored as an absolute angle: sun_offset_deg
is measured from the pole camera's viewing direction (CARLA gives the
azimuth the light travels from, hence the negative offsets), so the pole view is lit
from behind or from the side whatever the orientation of the crosswalk.
camera_overrides
¶
Camera attributes a preset needs, such as extra exposure for night scenes.
Source code in bikeped/sim/environment.py
settle_ticks
¶
Ticks to run after a weather change so auto exposure and wet surfaces settle.
Source code in bikeped/sim/environment.py
weather_values
¶
WeatherParameters fields for preset with an absolute sun azimuth.
Source code in bikeped/sim/environment.py
apply_weather
¶
Apply a preset field by field; returns the fields that were set.
Source code in bikeped/sim/environment.py
set_street_lights
¶
Switch street lights through the light manager when the server has one.
Source code in bikeped/sim/environment.py
ambient
¶
Background traffic and pedestrians around a scripted scenario.
Ambient actors make the rendered street look inhabited without getting in the way of the scripted agents. The scripted corridor is the bounding box of all scripted paths in the scenario frame plus a margin. Vehicles are spawned outside it, drive under the Traffic Manager and are stopped when they approach it. Walkers are spawned on the navigation mesh outside it, do not cross the road, and are sent back to where they started if they wander in.
The corridor helpers are plain numpy and need no simulator.
Ambient
¶
Ambient(
session: Any,
site: Any,
scenario: Dict[str, Any],
level: str = "none",
seed: int = 0,
night: bool = False,
)
Ambient vehicles and walkers for one render.
Every actor is spawned through the session, which tracks and destroys it. Spawning is best effort: a map without spawn points, a missing Traffic Manager or a full navigation mesh leaves the scene with fewer ambient actors and a log message, and never stops the render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Any
|
the running |
required |
site
|
Any
|
the |
required |
scenario
|
Dict[str, Any]
|
the scripted scenario; its paths define the corridor. |
required |
level
|
str
|
a key of :data: |
'none'
|
seed
|
int
|
seed of the blueprint, colour and spawn point choices. |
0
|
night
|
bool
|
switch vehicle lights on. |
False
|
Source code in bikeped/sim/ambient.py
counts
property
¶
Number of ambient vehicles and walkers alive, and of vehicles held back.
spawn
¶
Spawn the vehicles and walkers of the chosen level.
Source code in bikeped/sim/ambient.py
tick
¶
Update the ambient actors; call once before every world.tick().
Source code in bikeped/sim/ambient.py
stop
¶
Stop the walker controllers. The session destroys the actors.
Source code in bikeped/sim/ambient.py
corridor_bounds
¶
Bounding box of every scripted path point, grown by margin metres.
Returns (xmin, ymin, xmax, ymax) in the scenario frame.
Source code in bikeped/sim/ambient.py
expand_bounds
¶
Grow bounds by distance metres on every side.
in_corridor
¶
Whether the scenario-frame point (x, y) lies inside bounds.
distance_to_bounds
¶
Distance in metres from (x, y) to bounds, zero inside.
Source code in bikeped/sim/ambient.py
rigs
¶
Camera rigs: named views, their camera models and the CARLA sensors behind them.
A rig yields one :class:~bikeped.sim.types.CameraModel per tick (world frame,
see :mod:bikeped.sim.types) and owns the sensors that render it. Static rigs
(pole, street, bev, fisheye) never move; chase and
orbit move their sensor before every tick.
Views:
pole
Pinhole camera on the pole at the testbench camera position (12 ft), aimed
so the crosswalk and every scripted path fit in the frame.
fisheye
The deployed fisheye lens, rendered as cube faces and resampled with
:class:~bikeped.sim.fisheye.FisheyeRemap.
chase
Follows the first cyclist (or pedestrian) from behind and above.
orbit
Slow eye-level arc around the conflict point with a longer lens.
street
Static eye-level tripod on the kerb.
bev
Straight down from 60 m with a narrow lens, image up along scenario +y.
Rig
¶
One named view: the camera model(s) per tick and their sensors.
Source code in bikeped/sim/rigs.py
sensor_models
¶
move
¶
Place moving sensors for the frame rendered at t.
Source code in bikeped/sim/rigs.py
frame
¶
BGR image of this view and its auxiliary buffers from collected sensor data.
Source code in bikeped/sim/rigs.py
FollowRig
¶
FollowRig(
site: Site,
scenario: Dict[str, Any],
quality: str,
ground_truth: bool = False,
trajectories: Sequence[Trajectory] = (),
fps: int = 30,
)
Bases: Rig
Base of the moving views: an exponentially smoothed camera path.
Source code in bikeped/sim/rigs.py
rotation_to_basis
¶
Unreal (pitch, yaw, roll) degrees to world (forward, right, up).
Source code in bikeped/sim/rigs.py
look_at
¶
CARLA (pitch, yaw) in degrees of a level-horizon camera aimed at target.
Source code in bikeped/sim/rigs.py
pole_framing
¶
pole_framing(
site: Site, scenario: Dict[str, Any], aspect: float = 16 / 9, reach_m: float = 40.0
) -> Tuple[float, float, float]
Heading (rad, scenario frame), pitch (deg) and horizontal FOV (deg) of the pole view.
The view always contains the crosswalk (scenario x = 5, |y| <= 4) and
every path point within reach_m of the pole.
Source code in bikeped/sim/rigs.py
make_rig
¶
make_rig(
name: str,
site: Site,
scenario: Dict[str, Any],
quality: str,
*,
ground_truth: bool = False,
trajectories: Sequence[Trajectory] = (),
fps: int = 30,
) -> Rig
Build the rig called name (one of :data:RIG_NAMES).
Source code in bikeped/sim/rigs.py
describe_rigs
¶
Name and first docstring line of every rig, for presets.
Source code in bikeped/sim/rigs.py
runner
¶
Render one scenario end to end.
:func:render_scenario builds the trajectories, connects a :class:Session,
places the site, applies weather, spawns the cast and the camera rigs, warms
up, and then for every tick drives the actors, steps the world, collects the
frame-synchronised images, reads the simulated agent states, runs the decision
pipeline on the scripted positions exactly as the testbench does, attaches the
ground-truth danger and hands a :class:FrameRecord to the recorder.
RenderOptions
dataclass
¶
RenderOptions(
host: str = "127.0.0.1",
port: int = 2000,
engine: str = "auto",
map: Optional[str] = None,
crosswalk: int = 4,
crosswalks_file: Optional[str] = None,
rigs: Sequence[str] = ("pole",),
weather: Optional[str] = None,
drive: Optional[str] = None,
ambient: str = "none",
quality: str = "standard",
layout: str = "single",
overlay: bool = True,
save_frames: str = "none",
out: str = "renders",
seed: int = 0,
fps: int = 30,
pipeline_config: str = "default",
cyclist_proxy: Optional[str] = None,
ground_truth: bool = True,
warmup_s: float = 1.0,
max_frames: Optional[int] = None,
extra: Dict[str, Any] = dict(),
)
Everything render accepts besides the scenario itself.
resolve_scenario
¶
Look a scenario up by slug, name, suite:index or conformance index.
Source code in bikeped/sim/runner.py
danger_for
¶
Ground-truth danger at t as a JSON-friendly dict.
Source code in bikeped/sim/runner.py
clear_near_field
¶
Hide street furniture poles standing right in front of the pole camera.
The camera is mounted on a pole of its own; a lamp post a few metres in front of it would cover a large part of the image. Returns the ids of the disabled objects so they can be enabled again.
Source code in bikeped/sim/runner.py
render_scenario
¶
render_scenario(
scenario: Dict[str, Any],
opts: RenderOptions,
recorder_factory: Optional[Callable[..., Any]] = None,
) -> Dict[str, Any]
Render scenario on a running server; returns the recorder's summary.
Source code in bikeped/sim/runner.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
projection
¶
Rotation conventions and camera projection for rendered views.
All world quantities are in the CARLA world frame (metres, left-handed, z
up) and rotations are (pitch, yaw, roll) in degrees with the Unreal
convention of carla.Rotation. A camera is a :class:~bikeped.sim.types.CameraModel;
its camera coordinates are (f, r, u) along forward, right and up.
Pixel conventions follow the source of the intrinsics. Pinhole models use the
CARLA convention, principal point at (width / 2, height / 2). Fisheye models
use the calibration convention of camera_calibration.json and
decision_testbench.FisheyeCamera, in which pixel centres sit at integer
coordinates.
carla_rotation_to_basis
¶
Return the world-frame (forward, right, up) unit vectors of a rotation.
Angles are in degrees. The result equals carla.Transform(rotation=...)
.get_forward_vector(), .get_right_vector() and .get_up_vector().
Source code in bikeped/sim/projection.py
basis_to_carla_rotation
¶
basis_to_carla_rotation(
forward: Sequence[float], right: Sequence[float], up: Sequence[float]
) -> Tuple[float, float, float]
Return (pitch, yaw, roll) in degrees for an orthonormal camera basis.
Inverse of :func:carla_rotation_to_basis. At pitch of plus or minus 90
degrees only yaw + roll (or yaw - roll) is defined; roll is then set
to zero and the whole in-plane rotation goes into yaw.
Source code in bikeped/sim/projection.py
box_corners_world
¶
box_corners_world(
location: Sequence[float], rotation: Sequence[float], extent: Sequence[float]
) -> np.ndarray
Return the 8 world-frame corners of an oriented box as an (8, 3) array.
location is the box centre, rotation (pitch, yaw, roll) in
degrees, extent the half sizes along the box forward, right and up axes.
Corner 4*ix + 2*iy + iz lies on the minus (0) or plus (1) side of each
axis, so corners 0, 2, 6, 4 form the bottom face.
Source code in bikeped/sim/projection.py
world_to_camera
¶
Return camera coordinates (f, r, u) in metres of (N, 3) world points.
Source code in bikeped/sim/projection.py
fisheye_focal
¶
Equidistant focal length in pixels per radian of a fisheye model.
Source code in bikeped/sim/projection.py
camera_to_image
¶
Project camera coordinates (N, 3) to pixels; see :func:project_points.
Source code in bikeped/sim/projection.py
project_points
¶
Project world points to pixels.
Returns uv (N, 2), valid (N,) and depth (N,).
For a pinhole camera a point is valid in front of the near plane and depth
is the distance along the optical axis, as in a CARLA depth image. For a
fisheye a point is valid inside the field of view and depth is the
Euclidean range. Validity does not test the image bounds.
Source code in bikeped/sim/projection.py
project_polyline
¶
project_polyline(
points_w: ndarray,
cam: CameraModel,
*,
max_step_px: float = 6.0,
closed: bool = False,
) -> List[np.ndarray]
Project a world polyline to a list of image polylines (M, 2), M >= 2.
Pinhole segments are clipped exactly at the near plane and stay straight.
Fisheye segments are resampled so that consecutive samples are at most
about max_step_px apart, since straight lines map to curves, and the
polyline is split where it leaves the field of view.
Source code in bikeped/sim/projection.py
project_box
¶
Project an agent's oriented 3D box into a view.
Returns None when no part of the box is in front of the camera or
inside the image. Otherwise a dict with bbox [x1, y1, x2, y2]
clipped to the image, corners_image (8, 2) with NaN rows for
corners behind the near plane or outside the field of view,
truncation (fraction of the unclipped box area outside the image) and
distance_m (camera to box centre). Pinhole edges are clipped against
the near plane one by one, so a box that straddles the camera keeps its
true extent; fisheye edges are sampled densely because they curve.
Source code in bikeped/sim/projection.py
pixel_rays
¶
Return world-frame unit ray directions (N, 3) and a validity mask for pixels.
Source code in bikeped/sim/projection.py
pixel_to_ground
¶
pixel_to_ground(
uv: ndarray, cam: CameraModel, ground_z: float = 0.0
) -> Tuple[np.ndarray, np.ndarray]
Intersect pixel rays with the horizontal plane z = ground_z.
Returns world points (N, 3) (NaN where invalid) and valid (N,),
false for rays outside the field of view or not pointing at the plane.
Source code in bikeped/sim/projection.py
fisheye
¶
The deployed fisheye lens as a sim camera, and cube-face to fisheye remapping.
CARLA has no equidistant fisheye sensor, so the fisheye view is rendered as a
set of 90 degree pinhole cameras sharing one position (the faces of a cube
around the fisheye's optical axis) and resampled into the fisheye image with
a lookup table built once by :class:FisheyeRemap.
:func:deployed_fisheye_model reproduces the lens of the field deployment.
The calibration describes a 3500 x 3500 frame centred on the image circle; the
physical sensor is 3840 x 2160, which is that frame padded to 3840 x 3840 and
cropped to the middle 2160 rows, so the top and bottom of the circle are cut
(rows 670 to 2829 of the 3500 px frame are on the sensor). The sim camera
renders the sensor image, so its principal point is the calibrated one
shifted by (+170, -670) pixels. With the same pose it agrees with
decision_testbench.FisheyeCamera.world_to_pixel after that shift.
FisheyeRemap
¶
FisheyeRemap(
model: CameraModel,
face_size: int = 1024,
supersample: int = 1,
interpolation: int = cv2.INTER_LINEAR,
feather_px: float = 1.5,
)
Lookup table from cube-face pinhole images to a fisheye image.
Every face is a square face_size pinhole camera with a 90 degree field
of view at the fisheye position. Faces are oriented relative to the
fisheye's optical axis (front, right, back, left, up,
down); :attr:faces lists only those that receive pixels inside the
image circle and on the sensor. supersample renders the lookup at an
integer multiple of the output resolution and averages down, which
anti-aliases fine texture near the rim of the circle.
Source code in bikeped/sim/fisheye.py
face_camera
¶
Return the 90 degree square pinhole :class:CameraModel of a cube face.
Its basis converts to a CARLA rotation with
:func:~bikeped.sim.projection.basis_to_carla_rotation.
Source code in bikeped/sim/fisheye.py
face_rotation
¶
CARLA (pitch, yaw, roll) in degrees of a face camera.
remap
¶
Resample BGR face images into the fisheye image (uint8, black outside the circle).
face_images must hold every face in :attr:faces. Images of a
different size than face_size are accepted and sampled in proportion.
Source code in bikeped/sim/fisheye.py
deployed_fisheye_model
¶
deployed_fisheye_model(
position: Sequence[float],
yaw_deg: float = 0.0,
*,
pitch_deg: Optional[float] = None,
calibration: Optional[PathLike] = "camera_calibration.json",
config: Optional[PathLike] = "config.yaml",
scale: float = 1.0,
name: str = "fisheye",
) -> CameraModel
Return a :class:CameraModel of the deployed fisheye at position.
position is in world metres and yaw_deg is the CARLA yaw of the
optical axis. pitch_deg defaults to camera.pitch_deg in the config
(0, a level camera, as in the deployment and in the testbench). Intrinsics
come from the calibration file, falling back to the config; relative paths
are resolved against the repository root when not found in the working
directory. The projection is equidistant with optional k1/k2
terms and f = radius / (fov / 2), the same focal length the testbench
uses. scale resamples the 3840 x 2160 sensor (0.5 gives 1920 x 1080)
and scales the intrinsics to match.
Mapping to the testbench: a testbench heading h (scenario frame,
counter-clockwise from +x) is CARLA yaw -h once the scenario
y axis is flipped into the left-handed world, so the testbench default
(heading 90 degrees) is yaw_deg=-90.
Source code in bikeped/sim/fisheye.py
synthetic_faces
¶
synthetic_faces(
remap: FisheyeRemap,
pattern: str = "grid",
*,
ground_z: float = 0.0,
cell_m: float = 1.0,
markers: Sequence[Sequence[float]] = (),
) -> Dict[str, np.ndarray]
Render face images of an analytic scene, for tests and demos.
The scene is the plane z = ground_z (world metres) painted as a
checkerboard (pattern='checker') or a light grid on asphalt grey
(pattern='grid') with cell_m cells, under a vertical sky gradient.
Each entry of markers is a world (x, y) drawn as a pure red
(BGR (0, 0, 255)) disc of 0.15 m radius.
Source code in bikeped/sim/fisheye.py
groundtruth
¶
Per-frame ground truth: 2D boxes, visibility, danger labels and the closest pair.
Boxes come from :func:~bikeped.sim.projection.project_box on each agent's
oriented 3D box in the world frame. Danger labels come from
decision_testbench.compute_ground_truth_danger evaluated on the scripted
scenario, so the rendered runs carry the same labels as the paper's
evaluation. The synthetic helpers place testbench boxes in a world without a
simulator, for tests and demos.
danger_record
¶
Ground-truth danger at time t (seconds) as a JSON-safe dict.
Wraps decision_testbench.compute_ground_truth_danger; the keys are the
fields of its DangerAssessment (distances in metres, speeds in m/s,
times in seconds) and infinite values become None.
Source code in bikeped/sim/groundtruth.py
closest_pair
¶
Nearest scripted (bike_id, person_id, distance_m) in the scenario frame, or None.
Source code in bikeped/sim/groundtruth.py
scenario_to_world
¶
Default embedding of the right-handed scenario frame in the left-handed world.
Flips y. Used by the synthetic helpers; the CARLA runtime places
scenarios with its own site transform. A scenario heading h (radians)
becomes the world yaw -degrees(h).
Source code in bikeped/sim/groundtruth.py
synthetic_agents
¶
synthetic_agents(
scenario: Mapping[str, Any], t: float, ground_z: float = 0.0
) -> List[AgentState]
Scripted agents at time t with testbench box sizes.
Positions are placed with :func:scenario_to_world; speeds are in m/s.
Source code in bikeped/sim/groundtruth.py
synthetic_frame
¶
synthetic_frame(
scenario: Mapping[str, Any],
index: int,
fps: int,
cameras: Optional[Dict[str, CameraModel]] = None,
states: Optional[Sequence[str]] = None,
) -> FrameRecord
A :class:FrameRecord at t = index / fps built from the scenario alone, without images.
state is states[index] when given, else "idle"; in the alert
state alert_pair is the closest bike and pedestrian.
Source code in bikeped/sim/groundtruth.py
frame_ground_truth
¶
Per-agent ground truth of one view, JSON-safe.
Each entry has id, kind, role, bbox (pixels, clipped to
the image), corners_image (8 [u, v] or None), distance_m,
truncation and visible_fraction. The visible fraction is the share
of the agent's projected silhouette carrying its id in
aux['<view>/instance'] when that buffer and AgentState.instance_id
exist, else the share of camera-facing box surface samples not occluded in
aux['<view>/depth'] (planar depth for pinhole views, range for
fisheye views), else None. Agents outside the view are omitted.
Source code in bikeped/sim/groundtruth.py
overlay
¶
HUD overlay and schematic top-down panel for rendered scenario frames.
draw_overlay annotates one camera view with 3D boxes, id chips, ground
trails, the bike-pedestrian connector, the decision state badge and a timeline
of ground-truth danger against the system's alerts. draw_bev renders the
same frame as a plan view in the scenario frame. Both work on BGR uint8
arrays, return new arrays and scale every size with the image height, so 720p
and 4K output look the same.
Pixel coordinates follow bikeped.sim.projection: continuous, with pixel
i covering [i, i + 1).
Run python -m bikeped.sim.overlay --demo OUT_DIR to render a still and a
short clip over a synthetic backdrop without a simulator.
OverlayStyle
dataclass
¶
OverlayStyle(
background: str = "#0a0b0d",
text: str = "#ecebe8",
muted: str = "#9b9ca3",
cyclist: str = "#ffb547",
pedestrian: str = "#6fe3ff",
alert: str = "#ff5a4f",
warning: str = "#ffb547",
safe: str = "#5ad19a",
idle: str = "#6c6e76",
font_path: Optional[str] = None,
boxes: bool = True,
labels: bool = True,
trails: bool = True,
connector: bool = True,
rings: bool = False,
ring_views: Tuple[str, ...] = ("fisheye",),
badge: bool = True,
timeline: bool = True,
caption: bool = True,
trail_seconds: float = 1.5,
connector_max_m: float = 30.0,
scale: float = 1.0,
)
Appearance of the HUD and of the top-down panel.
Colours are #rrggbb strings and match the project site. The boolean
fields switch single elements. rings forces the range rings on for any
view; without it they are drawn only on the views named in ring_views,
where the camera footprint is the sensor position. scale multiplies
every size on top of the automatic scaling with image height, which is
useful when a view is shown small inside a composite.
build_timeline
¶
build_timeline(
scenario: Dict[str, Any], fps: int, states: Optional[Sequence[str]] = None
) -> Dict[str, Any]
Precompute what the timeline strip shows for one scenario.
Frame i is at t = i / fps. Ground-truth danger comes from
decision_testbench.compute_ground_truth_danger. states is the
decision state per frame as recorded by a run; when it is None the
states come from decision_testbench.simulate_scenario with the default
pipeline configuration and no detection noise, and the result is cached
per scenario and frame rate.
Returns a dict with duration (s), fps, n (frames), states,
the interval lists danger, actionable, alert and warning
([t0, t1] pairs in seconds, t1 exclusive), and first_alert_t
and first_danger_t (seconds or None).
Source code in bikeped/sim/overlay.py
draw_overlay
¶
draw_overlay(
image: ndarray,
frame: FrameRecord,
view: str,
*,
run: RunInfo,
scenario: Optional[Dict[str, Any]] = None,
style: Optional[OverlayStyle] = None,
history: Optional[Sequence[FrameRecord]] = None,
timeline: Optional[Dict[str, Any]] = None,
) -> np.ndarray
Draw the HUD over one rendered view and return the annotated copy.
image is the BGR uint8 frame of view and is not modified. The
camera model is frame.cameras[view]; without one only the screen-space
elements (badge, caption, timeline) are drawn. history holds earlier
frames, oldest first, and feeds the ground trails from the bottom centre of
each agent's box in the world frame. timeline is the result of
build_timeline; when it is None and scenario is given it is
built from the scenario at run.fps.
Source code in bikeped/sim/overlay.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | |
draw_bev
¶
draw_bev(
frame: FrameRecord,
*,
run: RunInfo,
scenario: Optional[Dict[str, Any]],
size: Tuple[int, int] = (1080, 1080),
style: Optional[OverlayStyle] = None,
history: Optional[Sequence[FrameRecord]] = None,
timeline: Optional[Dict[str, Any]] = None,
) -> np.ndarray
Render the frame as a schematic plan view in the scenario frame.
size is (width, height) in pixels. The panel shows the road, the
crosswalk at x = 5, the camera marker at run.site['camera_xy']
(the testbench camera position when absent) with the proximity rings of
the default pipeline, the scripted paths, and every agent as an oriented
glyph with a short trail. Scenario x points right and y up. Trails
come from the scenario paths when scenario is given and from
history otherwise. timeline adds the timeline strip at the bottom.
Source code in bikeped/sim/overlay.py
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
render_demo
¶
render_demo(
out_dir: Any,
scenario_id: str = "Bike Approaches Ped",
fps: int = 30,
size: Tuple[int, int] = (1920, 1080),
) -> Dict[str, Any]
Render the HUD and the plan view for one scenario without a simulator.
A pole-height pinhole camera at the testbench camera position looks at the
crosswalk over an analytic street backdrop, with agents placed from the
scenario paths. Writes demo_view.png (the camera view with the HUD),
demo_bev.png, demo_still.png (split layout), demo_fisheye.png
when the fisheye module is available, and demo.mp4. Returns the paths
under files together with the timeline of the scenario.
Source code in bikeped/sim/overlay.py
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 | |
main
¶
Command line entry point: python -m bikeped.sim.overlay --demo OUT_DIR.
Source code in bikeped/sim/overlay.py
compose
¶
Layouts that arrange camera views and the top-down panel into one frame.
All images are BGR uint8 arrays and sizes are (width, height) in
pixels. Every layout returns a frame of exactly the requested size, so the
composite video keeps one resolution whatever the views look like. Views are
never stretched: each one is scaled to fit its cell and centred on the page
background.
letterbox
¶
letterbox(
image: ndarray, size: Size, background: Tuple[int, int, int] = BACKGROUND_BGR
) -> np.ndarray
Fit image inside a frame of size without changing its aspect ratio.
The image is scaled to the largest size that fits (area averaging when it
shrinks, bicubic when it grows), centred, and the rest of the frame is
filled with background (BGR). Grayscale and BGRA inputs are converted
to BGR.
Source code in bikeped/sim/compose.py
fit_size
¶
Frame size at which a view fills its cell of layout without bars.
view_size is the (width, height) of the camera view, of which only
the aspect ratio matters, and height the wanted frame height in
pixels. The returned (width, height) is even in both dimensions, as
H.264 with 4:2:0 chroma requires.
Source code in bikeped/sim/compose.py
compose
¶
compose(
layout: str,
images: Sequence[ndarray],
bev: Optional[ndarray] = None,
*,
size: Size = (1920, 1080),
labels: Optional[Sequence[str]] = None,
) -> np.ndarray
Arrange camera views and the top-down panel into one frame.
Parameters¶
layout:
"single" shows the first view alone. "split" puts the first
view on the left and bev in a square panel on the right that spans
the inner height of the frame; without bev it is the same as
"single". "quad" is a 2x2 grid with up to three views and
bev in the last cell; without bev a fourth view takes that
cell, and cells with nothing to show stay background.
images:
Camera views, primary view first. A single array counts as one view.
bev:
Top-down panel, usually from overlay.draw_bev.
size:
(width, height) of the returned frame in pixels.
labels:
One short caption per view, drawn in the top-left corner of its cell.
Returns¶
numpy.ndarray
BGR uint8 frame of shape (height, width, 3). Margins and
gutters are 1.5 percent of the frame height and use the page
background colour.
Source code in bikeped/sim/compose.py
recorder
¶
Writes one rendered run to disk: videos, ground truth, stills and the manifest.
Layout of a run directory (run_id = <engine>_<scenario-id>_<weather>)::
<out_dir>/<run_id>/
manifest.json run metadata, camera models, per-frame records, timeline
video/<view>.mp4 clean view, H.264
video/<view>_overlay.mp4 view with the HUD (when overlay is on)
video/composite.mp4 the chosen layout
frames/<view>/000000.jpg only when frames are saved
gt/<view>.jsonl one line per frame: 2D boxes, 3D corners, visibility
stills/ first frame, first alert, closest bike-pedestrian approach
Videos are encoded with ffmpeg (libx264, yuv420p) through a pipe; when no
ffmpeg executable is found, cv2.VideoWriter with the mp4v codec is
used instead and a warning is logged.
VideoSink
¶
An H.264 mp4 writer fed with BGR uint8 frames of a fixed size.
The size is the first frame's size rounded up to even numbers, as yuv420p requires; later frames are padded or resized to it.
Source code in bikeped/sim/recorder.py
close
¶
Finish the file. Safe to call more than once.
Source code in bikeped/sim/recorder.py
Recorder
¶
Recorder(
out_dir: PathLike,
run: RunInfo,
*,
views: Sequence[str],
overlay: bool = True,
layout: str = "single",
save_frames: str = "none",
crf: int = 18,
scenario: Optional[Dict[str, Any]] = None,
style: Any = None,
composite_height: Optional[int] = None,
run_id: Optional[str] = None,
)
Collects :class:FrameRecord objects of one run and writes the run directory.
views are the view names to record from frame.images; the first
is the primary view used by the composite. overlay adds a HUD video
per view, layout is one of single, split (primary view plus a
plan view) or quad (up to three views plus a plan view).
save_frames is none, jpg or png. crf is the x264
quality (lower is better). scenario is the scenario dict; it feeds the
HUD timeline, the plan view and the manifest. composite_height sets
the composite's height in pixels (default: the primary view's height).
Use as a context manager, or call :meth:close; the manifest is written
on close even when rendering stopped with an exception.
Source code in bikeped/sim/recorder.py
write
¶
Record one frame: videos, ground truth, saved frames, still candidates.
Source code in bikeped/sim/recorder.py
timeline_summary
¶
Frame counts per state, alert and danger intervals, first alert and lead time.
lead_time_s is the onset of the first ground-truth danger interval
minus the first alert time (positive when the alert came first); it is
None unless both exist. Times are seconds of scenario time.
Source code in bikeped/sim/recorder.py
close
¶
Finish all files and write the manifest; returns paths and counts.
Returns {'run_dir', 'manifest', 'videos', 'stills', 'frames'}.
Calling it again returns the same result.
Source code in bikeped/sim/recorder.py
find_ffmpeg
¶
Path of an ffmpeg executable: the one on PATH, else the imageio-ffmpeg binary.
Source code in bikeped/sim/recorder.py
export
¶
Detection datasets from a rendered run.
A run directory written by bikeped.sim.recorder.Recorder holds the clean
video of every view, optionally the individual frames, and one ground-truth
file per view. The exporters here turn one view of a run into a COCO
annotation file or a YOLO dataset folder with the classes person and
bicycle.
Boxes are axis-aligned and given in pixels of the exported image, with the
origin at the top-left corner. Saved frames are copied as they are; when a
run has no saved frames the images are decoded from the clean video of the
view, whose frame k belongs to line k of the ground-truth file.
export_coco
¶
export_coco(
run_dir: PathLike,
out_path: PathLike,
view: str = "pole",
*,
min_visible: float = 0.0,
min_area: float = 0.0,
every: int = 1,
images_dir: Optional[PathLike] = None,
) -> Dict[str, Any]
Write one view of a run as a COCO detection dataset.
Parameters¶
run_dir:
Run directory with manifest.json and gt/<view>.jsonl.
out_path:
Annotation file to write. bbox is [x, y, width, height] in
pixels; the categories are person (id 1) and bicycle (id 2).
view:
Name of the camera view to export.
min_visible:
Drop boxes whose visible_fraction is known and below this value.
Boxes without a visibility estimate are kept.
min_area:
Drop boxes smaller than this area in square pixels.
every:
Export every every-th frame.
images_dir:
Folder for the images; images next to out_path by default.
file_name in the annotation file is relative to it.
Returns¶
dict
{"images": n, "annotations": m, "path": out_path}.
Source code in bikeped/sim/export.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
export_yolo
¶
export_yolo(
run_dir: PathLike,
out_dir: PathLike,
view: str = "pole",
*,
min_visible: float = 0.0,
min_area: float = 0.0,
every: int = 1,
) -> Dict[str, Any]
Write one view of a run as a YOLO detection dataset.
The output folder gets images/<run_id>_<view>_<frame>.jpg, a label
file with the same stem under labels/ and a data.yaml. Each label
line is class cx cy w h with the box centre and size divided by the
image width and height; class 0 is person and class 1 is bicycle.
Frames without boxes get an empty label file, so they count as negatives.
min_visible, min_area and every filter as in
:func:export_coco. Exports of several runs into the same folder add up,
because the file names carry the run id.
Returns¶
dict
{"images": n, "labels": m, "path": out_dir}, where m counts
the boxes written.
Source code in bikeped/sim/export.py
cli
¶
Command line interface: python -m bikeped.sim {probe,server,presets,render,export}.