PCL根据空间点云拟合圆

参考文档:

    //http://docs.pointclouds.org/1.9.1/classpcl_1_1_sample_consensus_model_circle3_d.html
    //使用PCL绘制空间圆
    //https://blog.csdn.net/zyj8691/article/details/79416733
    //http://www.pcl-users.org/RANSAC-Model-Coefficients-td4041435.html
    //http://www.pcl-users.org/SOLVED-Terrible-circle-fitting-results-with-SampleConsensusModelCircle3D-td4043214.html
    //http://docs.pointclouds.org/1.9.1/group__sample__consensus.html
    //[center.x, center.y, center.z, radius, normal.x, normal.y, normal.z]
    //http://pointclouds.org/documentation/tutorials/random_sample_consensus.php#random-sample-consensus

 

    pcl::PointCloud<pcl::PointXYZ>::Ptr final (new pcl::PointCloud<pcl::PointXYZ>);
    std::vector<int> inliersCircle3D;
    pcl::SampleConsensusModelCircle3D<PointT>::Ptr socCircle3D ( new pcl::SampleConsensusModelCircle3D<PointT> (oriCloud_inliers) );
    pcl::RandomSampleConsensus<PointT>::Ptr ransac ( new pcl::RandomSampleConsensus<PointT> (socCircle3D) );
    ransac->setDistanceThreshold(0.1f);
    ransac->computeModel();
    ransac->getInliers(inliersCircle3D);
    Eigen::VectorXf circle_coeff;
    ransac->getModelCoefficients(circle_coeff);
    PointCloud::Ptr finalCircle3D(new PointCloud);
    pcl::copyPointCloud (*oriCloud_inliers, inliersCircle3D, *finalCircle3D);
    std::cout<<"circle_coeff "<<"rows="<<circle_coeff.rows()<<"cols="<<circle_coeff.cols()<<"coefficeints="<<circle_coeff.size()<<std::endl;

 

circle_coeff rows=7cols=1coefficeints=7

#ifdef DEBUG_VIEW_CIRCLE3D
    pcl::visualization::PointCloudColorHandlerCustom<PointT> color_handler5(finalCircle3D, 230, 50, 12);//红色
    view->addPointCloud(finalCircle3D, color_handler5, "CH5");
    pcl::ModelCoefficients sphere_coeff3;
    sphere_coeff3.values.resize (4);
    sphere_coeff3.values[0] = circle_coeff(0, 0);
    sphere_coeff3.values[1] = circle_coeff(1, 0);
    sphere_coeff3.values[2] = circle_coeff(2, 0);
    sphere_coeff3.values[3] = circle_coeff(3, 0);//半径
    view->addSphere(sphere_coeff3, "sphere3");
#endif

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值