Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

PCL normal specific point

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <pcl/features/normal_3d_omp.h>
using namespace std;
int main()
{
    
	//--------------------- Load point cloud data ----------------------
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	if (pcl::io::loadPCDFile<pcl::PointXYZ>(" Car point cloud .pcd", *cloud) == -1)
	{
    
		PCL_ERROR("Could not read file
");
	}
	//-------------- Calculate the front of the cloud 10% The point normal of -----------------------
	vector<int> point_indices(floor(cloud->points.size() / 10));
	for (size_t i = 0; i < point_indices.size(); ++i) {
    
		point_indices[i] = i;	
	}
	//------------------- Pass index ----------------------------
	pcl::IndicesPtr indices(new vector <int>(point_indices));
	//------------------- Calculating normals ----------------------------
	pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> n;//OMP Speed up 
	n.setInputCloud(cloud);
	n.setIndices(indices);
	//  Create a kd Trees , Easy to search ; And pass it to the normal estimation class object created above 
	pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
	n.setSearchMethod(tree);
	n.setRadiusSearch(0.01);
	pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
	//---------------- Estimate characteristics ---------------
	n.compute(*normals);
	//------------- For convenience of visualization , Before the 10% Point cloud puts forward -------------------------------
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::copyPointCloud(*cloud, point_indices, *cloud1);
	//------------------ visualization -----------------------
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("Normal viewer"));
	// Set the background color 
	viewer->setBackgroundColor(0.3, 0.3, 0.3);
	viewer->addText("faxian", 10, 10, "text");
	// Set the point cloud color 
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color1(cloud1, 0, 225, 0);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 255, 0, 0);
	// Add coordinate system 
	//viewer->addCoordinateSystem(0.1);
	viewer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "sample cloud");
	viewer->addPointCloud<pcl::PointXYZ>(cloud1, single_color1, "sample cloud1");
	viewer->addPointCloudNormals<pcl::PointXYZ, pcl::Normal>(cloud1, normals, 20, 0.02, "normals");
	// Set the point cloud size 
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "sample cloud1");
	while (!viewer->wasStopped())
	{
    
		viewer->spinOnce(100);
		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}

	return 0;
}
Source by chowdera.com #
 
PREVIOUS NEXT
Tagged: #PCL #normal #specific #point
ADD COMMENT
Topic
Name
5+9 =