请选择 进入手机版 | 继续访问电脑版

点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 3433|回复: 1

求点云中近似落在平面上的点

[复制链接]
发表于 2017-2-16 11:00:20 | 显示全部楼层 |阅读模式

PCL内部已经实现了,直接调用方便啊,前面自己写了一个。今天看到了,就记录下。
pcl::SampleConsensusModelPlane<PointT>::selectWithinDistance (
  144
       const Eigen::VectorXf &model_coefficients, const double threshold, std::vector<int> &inliers)

  145
{

  146
   // Needs a valid set of model coefficients

  147
   if (model_coefficients.size () != 4)

  148
   {

  149
     PCL_ERROR ("[pcl::SampleConsensusModelPlane::selectWithinDistance] Invalid number of model coefficients given (%lu)!\n", model_coefficients.size ());

  150
     return;

  151
   }

  152

  153
   int nr_p = 0;

  154
   inliers.resize (indices_->size ());

  155
   error_sqr_dists_.resize (indices_->size ());

  156

  157
   // Iterate through the 3d points and calculate the distances from them to the plane

  158
   for (size_t i = 0; i < indices_->size (); ++i)

  159
   {

  160
     // Calculate the distance from the point to the plane normal as the dot product

  161
     // D = (P-A).N/|N|

  162
     Eigen::Vector4f pt (input_->points[(*indices_)].x,

  163
                         input_->points[(*indices_)].y,

  164
                         input_->points[(*indices_)].z,

  165
                         1);

  166
     

  167
     float distance = fabsf (model_coefficients.dot (pt));

  168
     

  169
     if (distance < threshold)

  170
     {

  171
       // Returns the indices of the points whose distances are smaller than the threshold

  172
       inliers[nr_p] = (*indices_);

  173
       error_sqr_dists_[nr_p] = static_cast<double> (distance);

  174
       ++nr_p;

  175
     }

  176
   }

  177
   inliers.resize (nr_p);

  178
   error_sqr_dists_.resize (nr_p);

  179
}


回复

使用道具 举报

 楼主| 发表于 2017-2-16 11:15:14 | 显示全部楼层
  1. pcl::SampleConsensusModelPlane<pcl::PointXYZ>::Ptr dit (new pcl::SampleConsensusModelPlane<pcl::PointXYZ> (source_cloud));

  2. Eigen::Vector4f coefficients = Eigen::Vector4f(a, b, c, d);
  3. std::vector<int> inliers;
  4. dit -> selectWithinDistance (coefficients, Threshold, inliers);
  5. pcl::copyPointCloud<pcl::PointXYZ>(*source_cloud, inliers, *new_cloud);
复制代码
回复 支持 反对

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-4-19 01:31 , Processed in 1.726838 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表