You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让PCL Fast Organized Mesh方法生成网格面?

解决PCL OrganizedFastMesh仅生成顶点无三角面的问题

核心原因

pcl::OrganizedFastMesh仅支持有序点云(Organized Point Cloud)——这类点云具备width和height属性,对应深度相机的像素行列结构,算法依赖点的行列邻接关系生成三角面。你的代码中仅用resize(size)创建点云,属于无序点云,无行列结构,因此无法生成面。

解决方案

1. 将点云转为有序结构

根据Intel RealSense D455的输出分辨率(常见如640×480、1280×720),设置点云的width和height,替代resize(size):

// 以640×480分辨率为例,总点数=640*480
int width = 640;
int height = 480;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = width;
cloud->height = height;
cloud->is_dense = false; // 若存在无效点(NaN),设为false
cloud->resize(width * height);

2. 修正代码语法错误

原代码中OrganizedFastMesh构造函数括号不匹配,修正为:

pcl::OrganizedFastMesh<pcl::PointXYZ>::Ptr orgMesh(new pcl::OrganizedFastMesh<pcl::PointXYZ>());

3. 可选:处理无效点

如果点云中存在NaN值(深度相机无法检测的区域),可开启跳过无效点的设置:

orgMesh->setSkipNaN(true);

修改后的完整代码示例

// 假设D455输出分辨率为640×480
int width = 640;
int height = 480;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = width;
cloud->height = height;
cloud->is_dense = false;
cloud->resize(width * height);

for (int i = 0; i < width * height; i++)
{
    cloud->at(i).x = Cloud[i].x;
    cloud->at(i).y = Cloud[i].y;
    cloud->at(i).z = Cloud[i].z;
}

std::cout << "Fast mesh started " << std::endl;
pcl::OrganizedFastMesh<pcl::PointXYZ>::Ptr orgMesh(new pcl::OrganizedFastMesh<pcl::PointXYZ>());
pcl::PolygonMesh triangles;

orgMesh->setTriangulationType(pcl::OrganizedFastMesh<pcl::PointXYZ>::TRIANGLE_RIGHT_CUT);
orgMesh->setSkipNaN(true); // 跳过无效点
orgMesh->setInputCloud(cloud);
orgMesh->reconstruct(triangles);

std::cout << "start saving the fast mesh obj..." << std::endl;
pcl::io::saveOBJFile("Mesh.obj", triangles);

验证

生成的OBJ文件中会出现f开头的面定义行(如f 1 2 3),表示由对应序号顶点组成的三角面。

内容的提问来源于stack exchange,提问作者Amayes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 17:06:32