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/plotBEVAndCamera.m

View on GitHub
function plotBEVAndCamera(trackData, cameraData)
%plotBEVAndCamera Side-by-side BEV actor plot and camera replay
%   plotBEVAndCamera(trackData, cameraData) displays a bird's-eye-view plot
%   of actor tracks alongside camera frames. Use when camera intrinsics are
%   NOT available (cannot project tracks onto image).
%
%   Supports both image-sequence cameras (Frames property with image files)
%   and video cameras (VideoFile property with .mp4/.avi).
%
%   IMPORTANT: Camera and track data MUST be synchronized (same number of
%   samples) before calling this function. If they are not, use the
%   "Crop & Sync" tab in the Driving Log Analyzer app to apply offset
%   correction and resample the data to matching rates.
%
%   Inputs:
%     trackData  — scenariobuilder.ActorTrackData object (normalized/synced)
%     cameraData — scenariobuilder.CameraData object (normalized/synced)

arguments
    trackData  scenariobuilder.ActorTrackData
    cameraData scenariobuilder.CameraData
end

% Verify data is synchronized (same number of samples)
assert(trackData.NumSamples == cameraData.NumSamples, ...
    "plotBEVAndCamera:unsynchronizedData", ...
    "Camera (%d samples) and track (%d samples) data are not synchronized. " + ...
    "Use the 'Crop & Sync' tab in the Driving Log Analyzer app to apply " + ...
    "offset correction and resample to matching rates.", ...
    cameraData.NumSamples, trackData.NumSamples);

% Detect if camera data is video-based or image sequence
% Video-based CameraData has Frames like "path/video.mp4/frame_N"
isVideo = false;
if cameraData.NumSamples > 0
    firstFrame = cameraData.Frames(1);
    % Check if it's a virtual frame path (contains video extension + /frame_)
    if contains(firstFrame, "/frame_") || contains(firstFrame, "\frame_")
        % Extract video file path (everything before /frame_N)
        parts = split(firstFrame, "/frame_");
        if isscalar(parts)
            parts = split(firstFrame, "\frame_");
        end
        videoFilePath = parts(1);
        if isfile(videoFilePath)
            isVideo = true;
            vidReader = VideoReader(videoFilePath);
        end
    end
end
if ~isVideo && cameraData.NumSamples > 0 && ~isfile(cameraData.Frames(1))
    % Fallback: if frames aren't readable files, try finding a video in the folder
    error("plotBEVAndCamera:unreadableFrames", ...
        "Cannot read camera frames. Frames path '%s' is not a valid file.", cameraData.Frames(1));
end

% Create side-by-side figure
f = figure(Position=[100 100 1400 550]);
tl = tiledlayout(f, 1, 2, TileSpacing="compact", Padding="compact");
camAx = nexttile(tl);
title(camAx, "Camera");
axis(camAx, "off");

bevAx = nexttile(tl);
bep = birdsEyePlot(Parent=bevAx, XLimits=[0 80], YLimits=[-30 30]);
trPlotter = trackPlotter(bep, LabelOffset=[1 0], Marker='^', ...
    MarkerEdgeColor='blue', MarkerFaceColor='cyan', DisplayName='Non-Ego Actors');
olPlotter = outlinePlotter(bep);
caPlotter = coverageAreaPlotter(bep, FaceColor=[0.6350 0.0780 0.1840]);
tsText = text(bevAx, 75, 12, "t=0.00s", FontSize=12, Color='b');

% Camera sensor coverage (approximate)
mountPosition = [1 0];
range = 60;
orientation = 0;
fieldOfView = 60;

numFrames = cameraData.NumSamples;

for j = 1:numFrames
    if ~isvalid(f)
        break;
    end

    % Read camera frame (image sequence or video)
    if isVideo
        if hasFrame(vidReader)
            img = readFrame(vidReader);
        else
            break;
        end
    else
        img = imread(cameraData.Frames(j));
    end

    % Display camera frame with timestamp
    camTs = cameraData.Timestamps(j);
    image(img, Parent=camAx);
    axis(camAx, "off");
    title(camAx, sprintf("Camera — t=%.2fs  (Frame %d/%d)", camTs, j, numFrames));

    % BEV actors (same index — data must be synchronized)
    positions = trackData.Position{j};
    trackIDs = trackData.TrackID{j};

    clearData(trPlotter);
    plotOutline(olPlotter, [0 0], 0, 4.7, 1.8, OriginOffset=[-1.35 0], Color=[0 0.447 0.741]);
    plotCoverageArea(caPlotter, mountPosition, range, orientation, fieldOfView);

    if ~isempty(positions)
        plotTrack(trPlotter, positions(:,1:2), string(trackIDs));
    end

    tsText.String = sprintf("t=%.2fs", camTs);

    drawnow;
    pause(0.03);
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