點雲實時顯示

激光雷達要用到點雲的實時顯示,所以記錄下來。

simpleVis(pcl::PointCloud<PointT>::ConstPtr cloud, pcl::PointCloud<PointT>::ConstPtr cloud2) {
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
	viewer->initCameraParameters();

	int v1(0);
	viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
	viewer->setBackgroundColor(0, 0, 0, v1);
	viewer->addText("Radius: 0.01", 10, 10, "v1 text", v1);
	pcl::visualization::PointCloudColorHandlerCustom<PointT> single_color0(cloud, 255, 0, 255);
	viewer->addPointCloud<PointT>(cloud, single_color0, "sample cloud0", v1);

	int v2(0);
	viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
	viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
	viewer->addText("Radius: 0.1", 10, 10, "v2 text", v2);
	pcl::visualization::PointCloudColorHandlerCustom<PointT> single_color(cloud, 0, 255, 0);
	viewer->addPointCloud<PointT>(cloud, single_color, "sample cloud", v2);

	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud0");
	viewer->addCoordinateSystem(1.0);

	return (viewer);
}

調用的時候:注意:viewer->spinOnce(100);
一定要記得放在合適的位置,否則無法顯示

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
//點雲實時顯示
viewer = simpleVis(cloud1, cloud1);
while (!viewer->wasStopped())
{
	…
pcl::visualization::PointCloudColorHandlerCustom<PointT> add_color1(cloud_cluster, rand() % 255, rand() % 255, rand() % 255);//添加隨機顏色
//更新到窗口sample cloud0
	viewer->updatePointCloud<pcl::PointXYZ>(cloud_cluster, add_color1, “sample cloud0”);
	viewer->spinOnce(100);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章