PCL根据空间点云拟合圆

大憨熊 提交于 2020-01-10 22:24:07

参考文档:

    //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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!