主要内容

读取激光雷达和摄像头数据,从Rosbag文件

这个例子展示了如何从rosbag文件中读取和保存图像和点云数据。本示例还演示了如何准备激光雷达摄像机校准数据。

属性从给定的URL下载rosbag文件helperDownloadRosbag辅助函数,在本例的最后定义。

outputFolder = fullfile (tempdir,“RosbagFile”);rosbagURL = [“https://ssd.mathworks.com/金宝appsupportfiles/lidar/data/”...“lccSample.zip”];helperDownloadRosbag (outputFolder rosbagURL);

从包文件中检索信息。

路径= fullfile (outputFolder,“lccSample.bag”);袋= rosbag(路径);

从rosbag中选择图像和点云消息,并通过使用适当的主题名称从文件中选择消息的子集。您还可以使用时间戳过滤数据。有关更多信息,请参见选择(ROS工具箱)函数。

imageBag =选择(包,“主题”/相机/图像/压缩的);pcBag =选择(包,“主题”“/点”);

阅读所有信息。

imageMsgs = readMessages (imageBag);pcMsgs = readMessages (pcBag);

为了准备激光雷达摄像机校准的数据,两个传感器的数据必须是时间同步的。创建timeseries(ROS工具箱)对象,并提取时间戳。

壹空间= timeseries (imageBag);ts2 = timeseries (pcBag);t1 = ts1.Time;t2 = ts2.Time;

为了精确校准,必须用相同的时间戳拍摄图像和点云。根据两个传感器的时间戳匹配相应的数据。考虑到不确定性,请使用0.1秒的余量。

k = 1;如果大小(t2, 1) >大小(t1, 1)i = 1:尺寸(t1, 1) [val, indx] = min (abs (t1 (i) - t2));如果Val <= 0.1 idx(k,:) = [i indx]; / /指定索引K = K + 1;结束结束其他的i = 1:尺寸(t2, 1) [val, indx] = min (abs (t2 (i) - t1));如果Val <= 0.1 idx(k,:) = [indx i]; / /指定索引K = K + 1;结束结束结束

创建目录来保存有效的图像和点云。

imageFilesPath = fullfile (tempdir,“PointClouds”);pcFilesPath = fullfile (tempdir,“图片”);如果~存在(imageFilesPath“dir”mkdir (imageFilesPath);结束如果~存在(pcFilesPath“dir”mkdir (pcFilesPath);结束

提取图像和点云。命名文件并将其保存在各自的文件夹中。将对应的图像和点云保存在相同的数字下。

i = 1:length(idx) i = readImage(imageMsgs{idx(i,1)});电脑= pointCloud (readXYZ (pcMsgs {idx(我,2)}));n_strPadded = sprintf (' % 04 d ', I);pcFileName = strcat (imageFilesPath,' / 'n_strPadded,“.pcd”);imageFileName = strcat (pcFilesPath,' / 'n_strPadded,“使用”);imwrite(我imageFileName);pcwrite (pc, pcFileName);结束

启动激光雷达相机校准器您也可以从MATLAB®命令行加载数据并启动应用程序。

checkerSize = 200;%毫米Padding = [0 0 0 0];lidarCameraCalibrator (imageFilesPath pcFilesPath、checkerSize、填充)

金宝app支持函数

函数helperDownloadRosbag (outputFolder rosbagURL)%从给定URL下载数据集到输出文件夹。rosbagFile = fullfile (outputFolder,“lccSample.bag”);rosbagZipFile = fullfile (outputFolder,“lccSample.zip”);如果~存在(rosbagFile“文件”如果~存在(rosbagZipFile“文件”mkdir (outputFolder);disp ('下载rosbag文件(8.5 MB)…');websave (rosbagFile rosbagURL);结束解压缩(rosbagZipFile outputFolder);结束结束