Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/automotive/matlab-use-scenario-builder

matlab-use-scenario-builder

Verified

Generate driving scenes, scenarios, road surfaces, and 3D content from scenariobuilder.* sensor data (GPS, camera, lidar, actor tracks) using Scenario Builder for Automated Driving Toolbox. BUILD, EXPORT, or AUGMENT a virtual scenario/scene/map: ego or actor trajectories, trajectory smoothing, OpenCRG road-surface extraction, 3D asset generation, static-object placement, point-cloud georeferencing + elevation, lane-based ego localization, sensor-fusion tracking, scenario-event extraction (cut-ins, hard brakes, near-misses, ADAS disengagements), or export to RoadRunner, drivingScenario, OpenDRIVE, OpenCRG, OpenSCENARIO, or Unreal Engine. Also: log-to-scenario, scenario harvesting, accident/near-miss reconstruction, SOTIF (ISO 21448) and ISO 26262 scenario coverage, USGS-aerial-lidar augmentation, traffic-sign placement, vision-based vehicle classification for actor assets. NOT for raw-data import or multi-sensor sync/crop/offset/timestamp normalization — route those to matlab-import-driving-data.

FileKindSize
SKILL.mdskill md56.6 KB
manifest.yamlconfig704 B
references/actortrackdata-api.mdmarkdown3.3 KB
references/example-roadrunner-scenario.mdmarkdown4.3 KB
references/example-scenario-from-gps-and-tracks.mdmarkdown9.6 KB
references/execution-rules-detail.mdmarkdown16.7 KB
references/gpsdata-api.mdmarkdown2.4 KB
references/osm-flat-scene-gotchas.mdmarkdown8.8 KB
references/per-frame-detections-to-actortrackdata.mdmarkdown7.8 KB
references/python-spkg-install-troubleshooting.mdmarkdown5.8 KB
references/trajectory-api.mdmarkdown13.7 KB
references/visualization-patterns.mdmarkdown12.4 KB
references/workflow-04-roadrunner-export-detail.mdmarkdown32.6 KB
references/workflow-07-height-correction.mdmarkdown3.3 KB
references/workflow-08-lane-localization.mdmarkdown39.1 KB
references/workflow-09-static-objects.mdmarkdown9.3 KB
references/workflow-10-road-surface-opencrg.mdmarkdown4.7 KB
references/workflow-11-point-cloud-georef.mdmarkdown4.5 KB
references/workflow-12-3d-asset-generation.mdmarkdown2.0 KB
references/workflow-13-event-extraction.mdmarkdown5.3 KB
references/workflow-14-sensor-fusion-tracking.mdmarkdown6.9 KB
references/workflow-15-driving-scenario-designer.mdmarkdown7.6 KB
references/workflow-16-aerial-lidar-augmentation.mdmarkdown14.4 KB
references/workflow-17-traffic-signs-from-sensor-data.mdmarkdown12.5 KB
references/workflow-18-vehicle-classification.mdmarkdown12.8 KB
references/workflow-19-ego-lane-inference.mdmarkdown10.0 KB
scripts/buildBestCropGrid.mother5.2 KB
scripts/openFile.mother716 B
scripts/plotActorCircles.mother3.5 KB
scripts/plotBEVAndCamera.mother4.2 KB

scripts/plotActorCircles.m

View on GitHub
function img = plotActorCircles(img, frameIdx, camObj, trackData, intrinsics, opts)
%plotActorCircles Overlay filled circles at actor center positions
%
%   img = plotActorCircles(img, frameIdx, camObj, trackData, intrinsics)
%   projects ego-relative actor positions onto the image and draws a
%   colored filled circle plus track-ID label per visible actor.
%
%   intrinsics is a struct with fields:
%     fx, fy   — focal lengths (pixels)
%     cx, cy   — principal point (pixels)
%     camHeight — camera mounting height above the ego origin (meters)
%
%   Optional:
%     ClassificationMap — containers.Map keyed by TrackID string, values
%       are structs with at least .RRCategory (e.g. "Sedan", "SUV").
%       When provided, label shows "ID <tid> | <RRCategory>".

arguments
    img
    frameIdx (1,1) double
    camObj   scenariobuilder.CameraData
    trackData scenariobuilder.ActorTrackData
    intrinsics (1,1) struct
    opts.ClassificationMap = []
end

ts = camObj.Timestamps(frameIdx);
[~, idx] = min(abs(trackData.Timestamps - ts));

trackIDs = trackData.TrackID{idx};
positions = trackData.Position{idx};

if isempty(trackIDs)
    return;
end

% Ego to camera: X-fwd,Y-left,Z-up -> X-right,Y-down,Z-forward
R_ego2cam = [0 -1 0; 0 0 -1; 1 0 0];
t_ego2cam = [0; intrinsics.camHeight; 0];

[h, w, ~] = size(img);
numActors = size(positions, 1);
pts = zeros(numActors, 2);
depths = zeros(numActors, 1);
labels = cell(numActors, 1);
nValid = 0;

for i = 1:numActors
    pos_ego = positions(i, :)';
    pos_ego(3) = 0.75; % approximate vehicle half-height (center of object)

    pos_cam = R_ego2cam * pos_ego + t_ego2cam;

    if pos_cam(3) <= 0
        continue;
    end

    u = intrinsics.fx * pos_cam(1) / pos_cam(3) + intrinsics.cx;
    v = intrinsics.fy * pos_cam(2) / pos_cam(3) + intrinsics.cy;

    if u >= 1 && u <= w && v >= 1 && v <= h
        nValid = nValid + 1;
        pts(nValid, :) = [round(u), round(v)];
        depths(nValid) = pos_cam(3);
        tid = char(trackIDs(i));
        if ~isempty(opts.ClassificationMap) && isKey(opts.ClassificationMap, tid)
            cls = opts.ClassificationMap(tid);
            labels{nValid} = sprintf('ID %s | %s %s', tid, cls.Color, cls.RRCategory);
        else
            labels{nValid} = tid;
        end
    end
end

pts = pts(1:nValid, :);
depths = depths(1:nValid);
labels = labels(1:nValid);

if nValid > 0
    % Distinct colors for different track IDs
    colors = [0 255 255; 255 100 100; 100 255 100; 255 200 0; ...
              200 100 255; 255 150 50; 100 200 255; 255 100 200; ...
              150 255 150; 255 255 100];

    % Scale radius based on image resolution and actor depth.
    % Base radius: 12px for 1920-wide image, scale proportionally.
    baseRadius = 12 * (w / 1920);
    refDepth = 20; % meters — reference depth for base radius

    for k = 1:nValid
        % Scale radius inversely with depth (farther = smaller).
        radius = max(4, round(baseRadius * refDepth / depths(k)));
        fontSize = max(10, round(16 * (w / 1920) * refDepth / depths(k)));

        cidx = mod(sum(double(labels{k})), size(colors,1)) + 1;
        c = colors(cidx,:);
        img = insertShape(img, "FilledCircle", [pts(k,:) radius], ...
            Color=c, Opacity=0.8);
        img = insertShape(img, "Circle", [pts(k,:) radius], ...
            Color="blue", LineWidth=2);
        img = insertText(img, pts(k,:) + [radius+3 -radius], labels{k}, ...
            FontSize=fontSize, TextColor=c, BoxColor="black", BoxOpacity=0.6);
    end
end

end

%% ----
% Copyright 2026 The MathWorks, Inc.
% ----
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 321kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 321kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 321kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 197kUpdated Claude CodeCodexVerifiedInstall