在 PCL 中可视化 PointNormal 点云的法线

Visualise normals of PointNormal point cloud in PCL

我正在尝试可视化包含在 pcl::PointNormal 点云中的法线。我尝试使用以下代码执行此操作:

std::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
std::mutex viewerMutex;

void viewerThreadFunction() {
    while(true) {
        if(viewer->wasStopped()) break;
        viewerMutex.lock();
        viewer->spinOnce();
        viewerMutex.unlock();
    }
}

int main() {
    viewer = std::shared_ptr<pcl::visualization::PCLVisualizer>(
                    new pcl::visualization::PCLVisualizer("Viewer"));
    viewer->setBackgroundColor(0, 0, 0);

    pcl::PointCloud<pcl::PointNormal>::Ptr cloud(new pcl::PointCloud<pcl::PointNormal>);

    viewer->addPointCloudNormals<pcl::PointNormal, pcl::PointNormal> (cloud, cloud, 25, 0.15, "normals"); // It throws an exception here:

    std::thread viewerThread{viewerThreadFunction};

    while(true) {
        // populate the point cloud
        viewerMutex.lock();
        viewer->removePointCloud("normals");
        viewer->addPointCloudNormals<pcl::PointNormal, pcl::PointNormal> (cloud, cloud, 25, 0.15, "normals");
        viewerMutex.unlock();
    }
}

我遇到异常:

terminate called after throwing an instance of 'std::bad_array_new_length'
    what(): std::bad_array_new_length
Aborted (core dumped)

我试图重写程序,viewer->addPointCloudNormals 仅在填充的点云上调用,但没有帮助。

您的查看器可能缺少实际的点云数据。

尝试添加

viewer->addPointCloud<pcl::PointNormal>(cloud, "foo", 1);

在调用 addpointcloudnormals 之前