The setting technique of the viewer background color in the pcl library and the three methods of coloring the point cloud

viewer.setBackgroundColor(0, 0, 0);

The three values ​​​​represent rgb

The range is 0-1, how you set the color is not what you want, but you can only set the above color, either all black, all white, or all red and other pure colors.

How to achieve the effect you want?

Look carefully at the values ​​in the code and the color values ​​in the rgb diagram below, and you will understand what's going on at once

viewer.setBackgroundColor(128.0 / 255.0, 138.0 / 255.0, 135.0 / 255.0);

 

The result of the operation is the color above

Change to another color, such as the color in cc

viewer.setBackgroundColor(8.0 / 255.0, 79.0 / 255.0, 117.0 / 255.0);

 

more colors

 

Coloring code for point cloud

//设置点云颜色
 
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>single_color(cloud,0,255,0); //设置背景色 viewer->setBackgroundColor(0,0,0.7)

 Color a field of the point cloud

boost::shared_ptr<pcl::visualization::PCLVisualizer> genericHandler(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
{
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Cloud"));
	pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> rgb(cloud, "y");
	viewer->addPointCloud(cloud, rgb, "sample cloud");
	return viewer;
}

 Coloring/gradienting the change of the point cloud along the Z direction

void visualize_pcdOne(pcl::PointCloud<pcl::PointXYZ>::Ptr pcd_src)
{

	//创建初始化目标
	pcl::visualization::PCLVisualizer viewer("3D Viewer");
	// 设置单一颜色
	//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> color_h(pcd_src, 0, 255, 0);//点云为绿色
	//按照z方向深度进行渲染(带渐变色)
	pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color_h(pcd_src, "z");
	// 添加坐标系
	viewer.addCoordinateSystem(0.3);    // 读取的点云单位是什么,这个单位就是什么
	viewer.setBackgroundColor(0.2, 0.2, 0.2);//背景色为深棕色
	viewer.addPointCloud<pcl::PointXYZ>(pcd_src, color_h, "source cloud");
	while (!viewer.wasStopped())
	{
		viewer.spinOnce(100);
		//boost 需要加头文件#include <boost/thread/thread.hpp>
		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}
}

Guess you like

Origin blog.csdn.net/sunnyrainflower/article/details/131309889