主要内容

select

Create reader for selected subset of ADTF DAT file data

描述

Use theselectobject function to create a reader for a selected subset of stream data to read from the ADTF DAT file. You can select streams using either the stream indices or stream name. Additionally, you can specify an index range or time range of data, to select from each of the specified streams. Theselectfunction returns anadtfStreamReader目的,which you can use to read data from the selected streams in the ADTF DAT file.

streamReader= select(adtfReader)creates anadtfStreamReader目的,streamReader,可以从汽车数据和时间触发的框架(ADTF)DAT文件中读取所有流中的数据adtfFileReaderobjectadtfReader.

example

streamReader= select(adtfReader,streamIndices)使用流索引从ADTF DAT文件指定流的子集streamIndices.

streamReader= select(adtfReader,streamName)使用流名称从ADTF DAT文件指定数据流streamName.

streamReader= select(___,Name=Value)specifies an additional option using oneName=Value除了先前语法的输入参数的任何组合外,对参数。您必须仅使用一个名称值参数,指定从所选流中读取的索引范围或时间范围。例如,IndexRange=[1 30]selects the first thirty frames of data from each selected stream.

例子

全部收缩

此示例显示了如何提取和可视化的视频流,该视频流存储在ADTF DAT文件中。它还显示了如何将视频流写入视频文件。

下载示例视频DAT文件。

downloadurl ='https://ssd.mathworks.com/supportfiles/driving/data/sample_can_video_dat.zip'; dataFolder = fullfile(tempdir,'adtf-video', filesep); options = weboptions('Timeout', Inf); zipFileName = [dataFolder,'sample_can_video_dat.zip']; folderExists = exist(dataFolder,'dir');%在临时目录中创建文件夹以保存下载的文件。if~folderExists mkdir(dataFolder); disp('Downloading sample_can_video_dat.zip (9.74 MB)...') websave(zipFileName, downloadURL, options);%提取下载文件的内容。disp('Extracting sample_can_video_dat.zip...')unzip(zipfileName,datafolter);end

创建ADTF文件读取器对象。

datfileName = fullfile(datafolder,"sample_can_video.dat");fileReader = adtfFileReader(datFileName)
fileReader = DataFileName: "C:\Users\latriwal\AppData\Local\Temp\adtf-video\sample_can_video.dat" DescriptionFileName: "" PluginDirectory: "" StreamCount: 2 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ __________ _______________ _________ __________ _________ 1 {'rawcan'} {'UNSUPPORTED'} 0 sec 14.805 sec 743 2 {'video' } {'adtf/image' } 0 sec 14.799 sec 149

From theStreaminfo属性,请注意视频流的索引为2。使用selectfunction of theadtfFileReader对象,选择用于阅读的视频流。返回adtfStreamReader对象具有有关选择的所有信息。

StreamReader = Select(FileReader,2)
StreamReader =带有属性的ADTFStreamReader:dataFileName:“ c:\ users \ latriwal \ appData \ local \ local \ temp \ adtf-video \ sample_can_video.dat” descriptionfileName:descriptionfileName:“启动时间:[0×0持续时间]末日:[0×0持续时间]数据载体:149

请注意,价值CurrentIndexOffsetis 0. This signifies that the nextreadnextcall will return the first item.

从流中预览第一个图像框架。

firstFrame = readNext(streamReader);imshow(firstframe.data.item)

Before creating a video, use the重置功能可以从第一帧开始阅读。这重置了CurrentIndexOffset到0。

重置(StreamReader);fprintf("CurrentIndexOffset = %d\n",streamReader.CurrentIndexOffset)
CurrentIndexOffset= 0

创建一个VideoWriter您可以用来将图像帧写入视频文件的对象。指定每秒1帧的帧速率。

VideOwriterObj = VideOwriter(“ example_video.avi”);videoWriterObj.FrameRate = 1; open(videoWriterObj);

Using thestreamReader目的,iterate over the data items in the selection one-by-one. ThehasNext函数确定是否有一个项目要读取,因为我们正在逐步读取文件。readnext返回基本上是包含数据和相关时间戳的结构的数据项。在每次迭代中,提取图像框架并将其写入视频文件。

尽管StreamReader.hasnext()streamData = streamReader.readNext();imageFrame = streamData.data.item;frame = im2frame(streamdata.data.item,灰色);writeVideo(VideOwriterObj,框架);end

Alternatively, you can read all the image frames at once, using the功能,然后迭代以后。

alldata =读(streamReader)
alldata =带有字段的结构:StreamIndex:2数据:[149×1结构]

关闭视频文件的连接。

close(videoWriterObj); close全部

Visualize the output fileexample_video.aviusingVideo Viewer.

implay(“ example_video.avi”)

Input Arguments

全部收缩

ADTF文件读取器,指定为adtfFileReader目的。

Linear indices of the streams to select, specified as a vector of positive integers.

要选择的流的名称,指定为字符串标量。

Name-Value Arguments

将可选的参数指定为Name=Value, whereNameis the argument name and价值是相应的值。该函数仅支持每个语法的一个名万博1manbetx称值参数,并且必须在其他参数之后出现。

例子:选择(adtfreader,indexrange = [1 10])从与指定的ADTF文件读取器关联的ADTF DAT文件的每个流中选择前10帧。

Index range of data to select from the selected streams, specified as a two-element vector of positive integers. The first element specifies the initial index to select from each stream, and the second element specifies the final index to select from each stream.

Time range of data to select from selected streams, specified as a two-elementdurationvector of the form[开始时间末日].

Output Arguments

全部收缩

Stream reader, returned as anadtfStreamReader目的。This object enables you to read data from the selected streams in the ADTF DAT file.

Version History

在R2022a中引入