点云分割的主要方法为:1、映射3D点云到2D的索引图上,对每个索引图上的像素点里面的点云进行高度,强度,数量的统计;2、对2D索引图进行CNN推断,从而得到每个像素点倾向的中心点,方向,所属类型的概率等;3、通过SPP引擎集群2D索引图上的像素点;4、对每个集群里的每个像素点求所属类型概率的平均值,从而得到集群所属的类型,点云的范围,中心点,高度等。从而完成了物体的识别。
这儿以单元测试cnn_segmentation_test.cc的测试cnn_segmentation_sequence_test为例来分析Apollo自动驾驶的点云CNN分割。
CNN分割测试用例
TEST(CNNSegmentationTest, cnn_segmentation_sequence_test) {
unsetenv("CYBER_PATH");
unsetenv("MODULE_PATH");
//设置工作目录和配置文件路经
FLAGS_work_root =
"/apollo/modules/perception/testdata/"
"lidar/lib/segmentation/cnnseg/";
FLAGS_config_manager_path = "../../../../../production/conf";
//实例化一个CNN分割类实例
auto segmentation = std::shared_ptr<cnnsegmentation>(new CNNSegmentation);
LidarDetectorOptions options;
EXPECT_FALSE(segmentation->Detect(options, nullptr));
LidarFrame frame_data;
EXPECT_FALSE(segmentation->Detect(options, &frame_data));
frame_data.cloud = base::PointFCloudPool::Instance().Get();
frame_data.world_cloud = base::PointDCloudPool::Instance().Get();
EXPECT_FALSE(segmentation->Detect(options, &frame_data));
//初始化CNN分割实例,包括参数加载,特征提取初始化,CNN推测初始化。见下面详细注解。
EXPECT_TRUE(segmentation->Init());
EXPECT_TRUE(segmentation->InitClusterAndBackgroundSegmentation());
std::string pcd_path =
"/apollo/modules/perception/testdata/lidar/app/data/";
std::vector<std::string> pcd_file_names;
common::GetFileList(pcd_path, ".pcd", &pcd_file_names);
std::string file_name;
std::sort(pcd_file_names.begin(), pcd_file_names.end(),
[](const std::string& lhs, const std::string& rhs) {
if (lhs.length() < rhs.length()) {
return true;
} else if (lhs.length() == rhs.length()) {
return lhs <= rhs;
} else {
return false;
}
});
for (size_t i = 0; i < pcd_file_names.size(); ++i) {
std::shared_ptr<lidarframe> frame(new LidarFrame);
frame->cloud = base::PointFCloudPool::Instance().Get();
frame->world_cloud = base::PointDCloudPool::Instance().Get();
//加载点云文件,比如这儿为/apollo/modules/perception/testdata/lidar/app/data/0001_00.pcd,可视化的结果如下图
if (!LoadPCDFile(pcd_file_names[i], frame->cloud)) {
continue;
}
frame->world_cloud->resize(frame->cloud->size());
//侦测当前帧中的对象,见下面代码详解
EXPECT_TRUE(segmentation->Detect(options, frame.get()));
//打印侦测到的对象信息,见下面代码详解
PrintObjects((frame.get())->segmented_objects);
}
}
</lidarframe></std::string></cnnsegmentation> |
TEST(CNNSegmentationTest, cnn_segmentation_sequence_test) {
unsetenv("CYBER_PATH");
unsetenv("MODULE_PATH");
//设置工作目录和配置文件路经
FLAGS_work_root =
"/apollo/modules/perception/testdata/"
"lidar/lib/segmentation/cnnseg/";
FLAGS_config_manager_path = "../../../../../production/conf";
//实例化一个CNN分割类实例
auto segmentation = std::shared_ptr<cnnsegmentation>(new CNNSegmentation);
LidarDetectorOptions options;
EXPECT_FALSE(segmentation->Detect(options, nullptr));
LidarFrame frame_data;
EXPECT_FALSE(segmentation->Detect(options, &frame_data));
frame_data.cloud = base::PointFCloudPool::Instance().Get();
frame_data.world_cloud = base::PointDCloudPool::Instance().Get();
EXPECT_FALSE(segmentation->Detect(options, &frame_data));
//初始化CNN分割实例,包括参数加载,特征提取初始化,CNN推测初始化。见下面详细注解。
EXPECT_TRUE(segmentation->Init());
EXPECT_TRUE(segmentation->InitClusterAndBackgroundSegmentation());
std::string pcd_path =
"/apollo/modules/perception/testdata/lidar/app/data/";
std::vector<std::string> pcd_file_names;
common::GetFileList(pcd_path, ".pcd", &pcd_file_names);
std::string file_name;
std::sort(pcd_file_names.begin(), pcd_file_names.end(),
[](const std::string& lhs, const std::string& rhs) {
if (lhs.length() < rhs.length()) {
return true;
} else if (lhs.length() == rhs.length()) {
return lhs <= rhs;
} else {
return false;
}
});
for (size_t i = 0; i < pcd_file_names.size(); ++i) {
std::shared_ptr<lidarframe> frame(new LidarFrame);
frame->cloud = base::PointFCloudPool::Instance().Get();
frame->world_cloud = base::PointDCloudPool::Instance().Get();
//加载点云文件,比如这儿为/apollo/modules/perception/testdata/lidar/app/data/0001_00.pcd,可视化的结果如下图
if (!LoadPCDFile(pcd_file_names[i], frame->cloud)) {
continue;
}
frame->world_cloud->resize(frame->cloud->size());
//侦测当前帧中的对象,见下面代码详解
EXPECT_TRUE(segmentation->Detect(options, frame.get()));
//打印侦测到的对象信息,见下面代码详解
PrintObjects((frame.get())->segmented_objects);
}
}
</lidarframe></std::string></cnnsegmentation>
测试用例PCD文件可视化结果
继续阅读“Apollo自动驾驶的点云CNN分割”本作品采用知识共享署名 4.0 国际许可协议进行许可。