估计不完成重叠点云配准后的重合度

这里写自定义目录标题

#include 
//点云重合率计算  para1 = 0.5   para2 =  0.15  
void IterationMatch::calaPointCloudCoincide(PointCloud::Ptr cloud_src, PointCloud::Ptr cloud_target,  float para1, float para2, float &coincide)
{
     
	pcl::registration::CorrespondenceEstimation<pcl::PointXYZ, pcl::PointXYZ> core;
	core.setInputSource(cloud_src);
	core.setInputTarget(cloud_target);

	boost::shared_ptr<pcl::Correspondences> cor(new pcl::Correspondences);   //共享所有权的智能指针,以kdtree做索引

	core.determineReciprocalCorrespondences(*cor, para1);   //点之间的最大距离,cor对应索引

	//构造重叠点云的PCD格式文件
	PointCloud overlapA;
	PointCloud overlapB;

	overlapA.width = cor->size();
	overlapA.height = 1;
	overlapA.is_dense = false;
	overlapA.points.resize(overlapA.width*overlapA.height);

	overlapB.width = cor->size();
	overlapB.height = 1;
	overlapB.is_dense = false;
	overlapB.points.resize(overlapB.width * overlapB.height);
	cout << "点云原来的数量:" << cloud_target->size() << endl;
	cout << "重合的点云数: " << cor->size() << endl;
	double num = 0;
	for (size_t i = 0; i < cor->size(); i++)
	{
     
		//overlapA写入pcd文件
		overlapA.points[i].x = cloud_src->points[cor->at(i).index_query].x;
		overlapA.points[i].y = cloud_src->points[cor->at(i).index_query].y;
		overlapA.points[i].z = cloud_src->points[cor->at(i).index_query].z;

		//overlapB写入pcd文件
		overlapB.points[i].x = cloud_target->points[cor->at(i).index_match].x;
		overlapB.points[i].y = cloud_target->points[cor->at(i).index_match].y;
		overlapB.points[i].z = cloud_target->points[cor->at(i).index_match].z;
		
		double dis = sqrt(pow(overlapA.points[i].x - overlapB.points[i].x, 2) + 
			pow(overlapA.points[i].y - overlapB.points[i].y, 2) +
			pow(overlapA.points[i].z - overlapB.points[i].z, 2));
		if (dis < para2)
			num++;
	}


	cout << "精配重叠区域的点云数:" << num << endl;
	cout << "重合率: " << float(num / cor->size())*100<< "%"<< endl;
	coincide = float(num / cor->size());

}

点云匹配后,如果是那种带不重叠区域匹配的,计算匹配的区域的点云的重合率

你可能感兴趣的:(pcl点云处理)