Main Content

play

Play video from camera data object

Since R2024b

Description

play(camData) plays the image frames from the camera data object camData.

example

play(camData,Name=Value) specifies options using one or more name-value arguments. For example, WaitTime=0.5 plays the image frames with a 0.5 second delay between image frames.

example

axesHandle = play(___) returns a figure handle as an Axes object using any combination of input arguments from previous syntaxes.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Examples

collapse all

Specify a sequence of image filenames.

images = {'Frame01.png','Frame02.png','Frame03.png','Frame04.png','Frame05.png', ...
    'Frame06.png','Frame07.png','Frame08.png','Frame09.png','Frame10.png'}';

Specify timestamps for each image frame.

timestamps = (0.1:0.1:1)';

Create an empty camera data object.

camData = scenariobuilder.CameraData
camData = 
  CameraData with properties:

                Name: ''

          NumSamples: 0
            Duration: 0
          SampleRate: 0
          SampleTime: 0
          Timestamps: []

              Frames: []
    SensorParameters: []

          Attributes: []

Add data samples to the camera data object.

add(camData,timestamps,images)

Play the camera data object.

play(camData)

Specify the path of an image that contains lanes.

filePath = fullfile(toolboxdir("vision"),"visiondata","highway.png");

Create an image datastore that contains two copies of the image.

imds = imageDatastore([filePath filePath]);

Specify timestamps for each image frame.

timestamps = (1:2)';

Create a camera data object using the specified timestamps and image datastore.

camData = scenariobuilder.CameraData(timestamps,imds)
camData = 
  CameraData with properties:

                Name: ''

          NumSamples: 2
            Duration: 1
          SampleRate: 2
          SampleTime: 1
          Timestamps: [2×1 double]

              Frames: {2×1 cell}
    SensorParameters: []

          Attributes: []

Initialize a laneBoundaryDetector object.

detector = laneBoundaryDetector;

Create a datastore from the camera data object.

ds = datastore(camData);

Detect the lane boundary points in the image by using the detect object function of the laneBoundaryDetector object.

laneDets = detect(detector,ds,ROI=120,ExecutionEnvironment="cpu")
laneDets=2×1 cell array
    {1×3 cell}
    {1×3 cell}

Add the lane detections as optional camera attributes to the camera data object.

camData.Attributes = laneDets;

Overlay the lane detections on the image frames, and play the camera data object.

play(camData,PlotFcn=@helperPlotLaneDetections)

% The helperPlotLaneDetections helper function overlays the lane detections as
% colored markers on the image frames.
function imgOut = helperPlotLaneDetections(~,imgIn,idx,obj)
laneDets = obj.Attributes{idx};
for i = 1:numel(laneDets)
    imgOut = insertMarker(imgIn,laneDets{1,i}(:,1:2),"o",Color="g",Size=3);
end
end

Input Arguments

collapse all

Camera data, specified as a CameraData object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: play(camData,WaitTime=0.5) plays the image frames with a 0.5 second delay between image frames.

Parent figure, specified as a Figure object or Panel object. If you do not specify Parent, the function plays the camera data in a new figure.

Delay between playing image frames, specified as a nonnegative scalar. Units are in seconds.

Custom plot function, specified as a function handle.

The function must support this syntax:

imgOut = plotFunction(axesHandle,imgIn,idx,obj),
where:

  • axesHandle — Figure handle of the axes on which to plot the image frames.

  • imgIn — Input image frame, specified as a P-by-Q-by-R array. P, Q, and R are the height, width, and the number of color channels of the image, respectively.

  • idx — Index of the input image frame, specified as an integer.

  • obj — Camera data, specified as a CameraData object.

The imgOut output argument returns the processed input image, returned as an image the same size as the input image imgIn.

Output Arguments

collapse all

Figure handle, returned as an Axes object.

Version History

Introduced in R2024b