Visualise normals of PointNormal point cloud in PCL

最后都变了- 提交于 2019-12-11 15:06:54

问题


I am trying to visualize normals that are contained in a pcl::PointNormal point cloud. I try to do this with following code:

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();
    }
}

I get an exception:

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

I tried to rewrite the program so, that viewer->addPointCloudNormals is called only on a populated point cloud, but it did not help.


回答1:


Your viewer might be missing the actual point cloud data.

try adding

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

before calling addpointcloudnormals



来源:https://stackoverflow.com/questions/48517352/visualise-normals-of-pointnormal-point-cloud-in-pcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!