gatherLabelData
Gather synchronized label data from ground truth
Syntax
Description
returns synchronized label data gathered from multisignal ground truth data,labelData
= gatherLabelData(gTruth
,signalNames
,labelTypes
)gTruth
。The function returns label data for the signals specified bysignalNames
and the label types specified bylabelTypes
。
[
additionally returns the signal timestamps associated with the gathered label data, using the arguments from the previous syntax.labelData
,timestamps
] = gatherLabelData(___)
Usetimestamps
with thewriteFrames
function to write the associated signal frames from thegroundTruthMultisignal
对象to disk. Use these frames and the associated labels as training data for machine learning or deep learning models.
[___] = gatherLabelData(___,'SampleFactor',
specifies the sample factor used to subsample label data.sampleFactor
)
Examples
Gather Label Data and Write Associated Signal Frames
Gather label data for a video signal and a lidar point cloud sequence signal from agroundTruthMultisignal
object. Write the signal frames associated with that label data to disk and visualize the frames.
添加的点云序列文件夹路径TLAB® search path. The video is already on the MATLAB search path.
pcSeqDir =局部e(toolboxdir('driving'),'drivingdata',。..'lidarSequence'); addpath(pcSeqDir);
Load agroundTruthMultisignal
object that contains label data for the video and the lidar point cloud sequence.
data = load('MultisignalGTruth.mat'); gTruth = data.gTruth;
Specify the signals from which to gather label data.
signalNames = ["video_01_city_c2s_fcw_10s""lidarSequence"];
The video contains rectangle labels, whereas the lidar point cloud sequence contains cuboid labels. Gather the rectangle labels from the video and the cuboid labels from the lidar point cloud sequence.
labelTypes = [labelType.Rectangle labelType.Cuboid]; [labelData,timestamps] = gatherLabelData(gTruth,signalNames,labelTypes);
Display the first eight rows of label data from the two signals. Both signals contain data for theCar
label. In the video, theCar
label is drawn as a rectangle bounding box. In the lidar point cloud sequence, theCar
label is drawn as a cuboid bounding box.
videoLabelSample = head(labelData{1}) lidarLabelSample = head(labelData{2})
videoLabelSample = table Car _________________ {[299 213 42 33]} lidarLabelSample = table Car ____________________________________________________ {[17.7444 6.7386 3.3291 3.6109 3.2214 3.5583 0 0 0]}
Write signal frames associated with the gathered label data to temporary folder locations, with one folder per signal. Use the timestamps returned by thegatherLabelData
function to indicate which signal frames to write.
outputFolder = fullfile(tempdir,["videoFrames""lidarFrames"]); fileNames = writeFrames(gTruth,signalNames,outputFolder,timestamps);
Writing 2 frames from the following signals: * video_01_city_c2s_fcw_10s * lidarSequence
Load the written video signal frames by using animageDatastore
object. Load the associated rectangle label data by using aboxLabelDatastore
object.
imds = imageDatastore(fileNames{1}); blds = boxLabelDatastore(labelData{1});
Load the written lidar signal frames by using afileDatastore
object. Load the associated cuboid label data by using aboxLabelDatastore
object.
fds = fileDatastore(fileNames{2},'ReadFcn',@pcread); clds = boxLabelDatastore(labelData{2});
Visualize the written video frames by using avision.VideoPlayer
object. Visualize the written lidar frames by using apcplayer
object.
videoPlayer = vision.VideoPlayer; ptCloud = preview(fds); ptCloudPlayer = pcplayer(ptCloud.XLimits,ptCloud.YLimits,ptCloud.ZLimits);whilehasdata(imds)% Read video and lidar frames.I = read(imds); ptCloud = read(fds);% Visualize video and lidar frames.videoPlayer(I); view(ptCloudPlayer,ptCloud);end
Remove the path to the point cloud sequence folder.
rmpath(pcSeqDir);
Input Arguments
gTruth
—Multisignal ground truth data
groundTruthMultisignal
object|vector ofgroundTruthMultisignal
对象
Multisignal ground truth data, specified as agroundTruthMultisignal
object or vector ofgroundTruthMultisignal
对象。
EachgroundTruthMultisignal
object ingTruth
must include all the signals specified in thesignalNames
input.
In addition, each object must include at least one marked label per gathered label definition. SupposegTruth
is agroundTruthMultisignal
对象包含标签数据or a single video signal namedvideo_front_camera
。The object contains marked rectangle region of interest (ROI) labels for thecar
label definition but not for thetruck
label definition. If you use this syntax to gather labels of typeRectangle
from this object, then thegatherLabelData
function returns an error.
labelData = gatherLabelData(gTruth,"video_front_camera",labelType.Rectangle);
signalNames
—Names of signals
character vector|string scalar|cell array of character vectors|string array
Names of the signals from which to gather label data, specified as a character vector, string scalar, cell array of character vectors, or string vector. The signal names must be valid signal names stored in the input multisignal ground truth data,gTruth
。
To obtain the signal names from agroundTruthMultisignal
object, use this syntax, wheregTruth
is the variable name of the object:
gTruth.DataSource.SignalName
Example:'video_01_city_c2s_fcw_10s'
Example:"video_01_city_c2s_fcw_10s"
Example:{'video_01_city_c2s_fcw_10s','lidarSequence'}
Example:["video_01_city_c2s_fcw_10s" "lidarSequence"]
labelTypes
—Label types
labelType
enumeration scalar|labelType
enumeration vector|cell array oflabelType
enumeration scalars and vectors
Label types from which to gather label data, specified as alabelType
enumeration scalar,labelType
enumeration vector, or a cell array oflabelType
enumeration scalars and vectors. ThegatherLabelData
function gathers label data for each signal specified by inputsignalNames
and eachgroundTruthMultisignal
object specified by inputgTruth
。The number of elements inlabelTypes
must match the number of signals insignalNames
。
Gather Label Data for Single Label Type per Signal
To gather label data for a single label type per signal, specifylabelTypes
as alabelType
enumeration scalar or vector. Across allgroundTruthMultisignal
对象ingTruth
,gatherLabelData
function gatherslabelTypes(n)
label data fromsignalName(n)
, wheren
is the index of the label type and the corresponding signal name whose label data is to be gathered. Each returned table in the outputlabelData
cell array contains data for only one label type per signal.
In this code sample, thegatherLabelData
function gathers labels of typeRectangle
from a video signal namedvideo_front_camera
。The function also gathers labels of typeCuboid
from a lidar point cloud sequence signal stored in a folder namedlidarData
。ThegTruth
input contains thegroundTruthMultisignal
对象from which this data is to be gathered.
labelData = gatherLabelData(gTruth,。..["video_front_camera","lidarData"],。..[labelType.Rectangle,labelType.Cuboid];
To gather label data for a single label type from separate signals, you must repeat the label type for each signal. In this code sample, thegatherLabelData
function gathers labels of typeRectangle
from thevideo_left_camera
andvideo_right_camera
video signals.
labelData = gatherLabelData(gTruth,。..["video_left_camera","video_right_camera"],。..[labelType.Rectangle,labelType.Rectangle];
Gather Label Data for Multiple Label Types per Signal
To gather label data for multiple label types per signal, specifylabelTypes
as a cell array oflabelType
enumeration scalars and vectors. Across allgroundTruthMultisignal
对象ingTruth
,gatherLabelData
function gatherslabelTypes{n}
label data fromsignalName(n)
, wheren
is the index of the label types and the corresponding signal name whose label data is to be gathered. The function groups the data for these label types into one table per signal pergroundTruthMultisignal
object.
In this code sample, thegatherLabelData
function gathers labels of typeRectangle
andLine
from thevideo_front_camera
video signal. The function also gathers labels of typeCuboid
from a lidar point cloud sequence signal stored in a folder namedlidarData
。ThegTruth
input contains thegroundTruthMultisignal
对象from which this data is to be gathered.
labelData = gatherLabelData(gTruth,。..["video_front_camera",。.."lidarData"],。..{[labelType.Rectangle labelType.Line],。..labelType.Cuboid};
Valid Enumeration Types
You can specify one or more of these enumeration types.
labelType.Rectangle
— Rectangle ROI labelslabelType.Cuboid
— Cuboid ROI labels (point clouds)labelType.ProjectedCuboid
— Projected cuboid ROI labels (images and video data)labelType.Line
— Line ROI labelslabelType.PixelLabel
— Pixel ROI labelslabelType.Polygon
— Pixel ROI labelslabelType.Scene
— Scene labels
To gather label data for scenes, you must specifylabelTypes
as thelabelType.Scene
enumeration scalar. You cannot specify any other label types withlabelType.Scene
。
sampleFactor
—Sample factor
1
(default) |positive integer
Sample factor used to subsample label data, specified as a positive integer. A sample factor ofK
includes everyK
th signal frame. Increase the sample factor to drop redundant frames from signals with high sample rates, such as videos.
Example:'SampleFactor',5
Output Arguments
labelData
— Label data
cell array of tables
Label data, returned as anM
-by-N
cell array of tables, where:
M
is the number ofgroundTruthMultisignal
对象ingTruth
。When
labelTypes
contains ROIlabelType
enumerations,N
is the number of signals insignalNames
and the number of elements inlabelTypes
。In this case,labelData{m,n}
contains a table of label data for then
th signal ofsignalNames
that is in them
thgroundTruthMultisignal
object ofgTruth
。The table contains label data for only the label types in then
th position oflabelTypes
。When
labelTypes
contains only thelabelType.Scene
enumeration,N
is equal to1
。In this case,labelData{m}
contains a table of scene label data across all signals in them
thgroundTruthMultisignal
object ofgTruth
。
For a given label data table,tbl
,table is of sizeT
-by-L
, where:
T
is the number of timestamps in the signal for which label data exists.L
is the number of label definitions that are of the label types gathered for that signal.tbl(t,l)
contains the label data gathered for thel
th label at thet
th timestamp.
If one of the signals has no label data at a timestamp, then the corresponding label data table does not include a row for that timestamp.
For each cell in the table, the format of the returned label data depends on the type of label.
Label Type | Storage Format for Labels at Each Timestamp |
---|---|
labelType.Rectangle |
|
|
The figure shows how these values determine the position of a cuboid. |
|
The figure shows how these values determine the position of a cuboid.
|
labelType.Line |
|
labelType.PixelLabel |
Label data for all pixel label definitions is stored in a singleM-by-1 |
labelType.Polygon |
|
labelType.Scene |
Logical1 (true ) if the scene label is applied, otherwise logical0 (false ) |
Label Data Format
Consider a cell array of label data gathered by using thegatherLabelData
function. The function gathers labels from threegroundTruthMultisignal
对象with variable namesgTruth1
,gTruth2
, andgTruth3
。
For a video signal named
video_front_camera
,function gathers labels of typeRectangle
andLine
。For a lidar point cloud sequence signal stored in a folder named
lidarData
,function gathers labels of typeCuboid
。
This code shows the call to thegatherLabelData
function.
labelData = gatherLabelData([gTruth1 gTruth2 gTruth3],。..["video_front_camera",。.."lidarData"],。..{[labelType.Rectangle labelType.Line],。..labelType.Cuboid};
labelData
output is a 3-by-2 cell array of tables. Each row of the cell array contains label data for one of thegroundTruthMultisignal
对象。The first column contains the label data for the video signal,video_front_camera
。The second column contains the label data for the point cloud sequence signal,lidarData
。This figure shows thelabelData
cell array.
This figure shows the label data table for the video signal in the thirdgroundTruthMultisignal
object. ThegatherLabelData
function gathered data for aRectangle
label namedcar
and aLine
label namedlane
。The table contains label data at four timestamps in the signal.
This figure shows the label data table for the lidar signal in the thirdgroundTruthMultisignal
object. ThegatherLabelData
function gathered data for aCuboid
label, also namedcar
。Thecar
label appears in both signal types because it is marked as aRectangle
label for video signals and aCuboid
label for lidar signals. The table contains label data at four timestamps in the signal.
timestamps
— Signal timestamps
cell array ofduration
vectors
Signal timestamps, returned as anM
-by-N
cell array ofduration
vectors, where:
M
is the number ofgroundTruthMultisignal
对象ingTruth
。N
is the number of signals insignalNames
。labelData{m,n}
contains the timestamps for then
th signal ofsignalNames
that is in them
thgroundTruthMultisignal
object ofgTruth
。
If you gather label data from multiple signals, the signal timestamps are synchronized to the timestamps of the first signal specified bysignalNames
。
Limitations
The
gatherLabelData
function does not gather label data for sublabels or attributes. If a label contains sublabels or attributes, in thelabelData
output, the function returns the position of the parent label only.
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- 加拿大(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)