PCL编程->基于PFH特征匹配测试

基于PFH特征匹配的测试函数如下:

void algoritmpfh()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr target(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr ptr1(new pcl::PointCloud<pcl::PointXYZ>);
	//pcl::io::loadPCDFile("table_scene_mug_stereo_textured.pcd", *target);
	
	pcl::io::loadPCDFile("0000.pcd", *target);
	//pcl::PointXYZ min_coordinate, max_coordinate;
	//ofstream fout("results.txt", ios::app);
	pcl::VoxelGrid<pcl::PointXYZ> sor;
	sor.setInputCloud(target);
	sor.setLeafSize(15, 15, 15);
	sor.filter(*ptr1);
	pcl::io::savePCDFileBinary("0001.pcd",*ptr1);
	//pcl::getMinMax3D(*ptr1, min_coordinate, max_coordinate);
	// Create the normal estimation class, and pass the input dataset to it
	pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
	ne.setInputCloud(ptr1);

	// Create an empty kdtree representation, and pass it to the normal estimation object.
	// Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
	pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
	ne.setSearchMethod(tree);

	// Output datasets
	pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);

	// Use all neighbors in a sphere of radius 3cm
	ne.setRadiusSearch(50);

	// Compute the features
	ne.compute(*cloud_normals);

	// Create the PFH estimation class, and pass the input dataset+normals to it
	pcl::PFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::PFHSignature125> pfh;
	pfh.setInputCloud(ptr1);
	pfh.setInputNormals(cloud_normals);
	// alternatively, if cloud is of tpe PointNormal, do pfh.setInputNormals (cloud);

	// Create an empty kdtree representation, and pass it to the PFH estimation object.
	// Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
	//pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
	//pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree (new pcl::KdTreeFLANN<pcl::PointXYZ> ()); -- older call for PCL 1.5-
	pfh.setSearchMethod(tree);

	// Output datasets
	pcl::PointCloud<pcl::PFHSignature125>::Ptr pfhs(new pcl::PointCloud<pcl::PFHSignature125>());

	// Use all neighbors in a sphere of radius 5cm
	// IMPORTANT: the radius used here has to be larger than the radius used to estimate the surface normals!!!
	pfh.setRadiusSearch(0.05);

	// Compute the features
	pfh.compute(*pfhs);

	// cloud_normals->points.size () should have the same size as the input cloud->points.size ()*
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
	viewer.reset(new pcl::visualization::PCLVisualizer("viewer", true));
	//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handle(ptr1, 0, 255, 0);
	//viewer->addPointCloud(ptr1, handle, "cloud");
	viewer->addPointCloudNormals<pcl::PointXYZ, pcl::Normal>(ptr1, cloud_normals);
	//viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
	viewer->resetCamera();

	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
	}
	system("pause");
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值