How to visualize a sequence of TOF-Sensor data in PCL (with Qt)?

狂风中的少年 提交于 2020-01-02 19:29:27

问题


I've this TOF-sensor and I want to visualize the sensor's data as a point-cloud in Qt. I converted the data into a pcl::PointCloud and now I want to visualize it.

The API of the sensor would emit a picture whenever one was created. And I would send it to the QVTKWidget to visualize it. And I tried it with this snippet of code (which I got from here):

pcl::visualization::PCLVisualizer pvis ("test_vis", false); 
// 'false' prevents PCLVisualizer's own window to pop up

pvis.addPointCloud<pcl::PointXYZ>(pc); // pc is my point cloud

vtkSmartPointer<vtkRenderWindow> renderWindow = pvis.getRenderWindow();
widget.SetRenderWindow(renderWindow);

But it seems like this is only meant to visualize one steady point-cloud and not a changing sequence of point-clouds.

Question: Is there any way to update the cloud_xyz whenever my sensor emits a new picture?


回答1:


OK, after some trying, here is my solution:

in my VTKPointCloudWidget which inherits from QVTKWidget:

pcl::visualization::PCLVisualizer vis ("vis", false); 

VTKPointCloudWidget::VTKPointCloudWidget(QWidget *parent) : QVTKWidget(parent)
{
   this->resize(500, 500);
   pcl::PointCloud<pcl::PointXYZ>::Ptr pc (new pcl::PointCloud<pcl::PointXYZ>);

   vis.addPointCloud<pcl::PointXYZ>(pc);
   vtkSmartPointer<vtkRenderWindow> renderWindow = vis.getRenderWindow();
   this->SetRenderWindow(renderWindow);
   this->show();
}

and whenever a new sensor image is emitted, it is sent to:

void VTKPointCloudWidget::showPointCloud(SensorPicture pic)
{   
   // converts the sensor image to a point cloud
   pcl::PointCloud<pcl::PointXYZ>::Ptr pc = cvtSP2PC(pic);

   pc->width = pic.width;
   pc->height = pic.height;

   vis.updatePointCloud<pcl::PointXYZ>(pc); 

   this->update();
}


来源:https://stackoverflow.com/questions/11918650/how-to-visualize-a-sequence-of-tof-sensor-data-in-pcl-with-qt

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