当前位置: 首页>>代码示例>>C++>>正文


C++ Filter::DeSamping方法代码示例

本文整理汇总了C++中Filter::DeSamping方法的典型用法代码示例。如果您正苦于以下问题:C++ Filter::DeSamping方法的具体用法?C++ Filter::DeSamping怎么用?C++ Filter::DeSamping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filter的用法示例。


在下文中一共展示了Filter::DeSamping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char** argv)
{
    // Initialize ROS
    ros::init (argc, argv, "objectMaster");
    ros::NodeHandle n;
    ros::Rate waiting_rate(30);

    //strat a traver and wait for its ready
    cloudTraver ct(n);
    while(!ct.isReady())
    {
        ros::spinOnce();
        waiting_rate.sleep();
    }


    cvNamedWindow("CurrentImage",CV_WINDOW_AUTOSIZE);
    cv::Mat image;
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloudP;

    Mat src, dst, color_dst;
    std::string objectNameTemp="TEMP";
    int count=0;
    while(ros::ok())
    {
        while(!ct.isReady())
        {
            ros::spinOnce();
        }

        image=ct.getImage();
        cloudP=ct.getCloud();

        if(cloudP->empty())
        {
            std::cout<<"No pointCloud passed into this process, fuck you no points you play MAOXIAN!"<<std::endl;
            continue;
        }
        pcl::PointCloud<PointType>::Ptr cloud_RGBA(new pcl::PointCloud<PointType>);
        *cloud_RGBA=*cloudP;

        Filter filter;
        cloud_RGBA=filter.PassThrough(cloud_RGBA);
        cloud_RGBA=filter.DeSamping(cloud_RGBA);
        cloud_RGBA=filter.RemovePlane(cloud_RGBA);
        if(cloud_RGBA->empty())
        {
            std::cout<<"No pointCloud left after the samping"<<std::endl;
            continue;
        }

        std::vector<pcl::PointIndices> cluster_indices;
        filter.ExtractionObject(cloud_RGBA,cluster_indices);

        if(cluster_indices.size()!=0)
        {
            std::cout<<cluster_indices.size()<<"clusters extraced"<<std::endl;
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_f (new pcl::PointCloud<pcl::PointXYZRGBA>);
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_filtered (new 	pcl::PointCloud<pcl::PointXYZRGBA>);
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud = cloud_RGBA;
            //voxelgrid并不是产生球面空洞的原因
            pcl::VoxelGrid<pcl::PointXYZRGBA> vg;
            vg.setInputCloud (cloud);
            vg.setLeafSize (0.01f, 0.01f, 0.01f);
            vg.filter (*cloud_filtered);
            //Create the segmentation object for the planar model and set all the parameters
            pcl::SACSegmentation<pcl::PointXYZRGBA> seg;
            pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
            pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_plane (new pcl::PointCloud<pcl::PointXYZRGBA> ());
            pcl::PCDWriter writer;
            seg.setOptimizeCoefficients (true);
            seg.setModelType (pcl::SACMODEL_PLANE);
            seg.setMethodType (pcl::SAC_RANSAC);
            seg.setMaxIterations (100);
            seg.setDistanceThreshold (0.02);
            //.........
            int i=0, nr_points = (int) cloud_filtered->points.size ();
            while (cloud_filtered->points.size () > 0.3 * nr_points)
            {
                // Segment the largest planar component from the remaining cloud
                seg.setInputCloud (cloud_filtered);
                seg.segment (*inliers, *coefficients);
                if (inliers->indices.size () == 0)
                {
                    std::cout << "Could not estimate a planar model for the given dataset." << std::endl;
                    break;
                }

                // Extract the planar inliers from the input cloud
                pcl::ExtractIndices<pcl::PointXYZRGBA> extract;
                extract.setInputCloud (cloud_filtered);
                extract.setIndices (inliers);
                extract.setNegative (false);

                // Get the points associated with the planar surface
                extract.filter (*cloud_plane);
                //std::cout << "PointCloud representing the planar component: " << cloud_plane->points.size () << " data points." << std::endl;

                // Remove the planar inliers, extract the rest
//.........这里部分代码省略.........
开发者ID:kidozh,项目名称:opencv,代码行数:101,代码来源:objectMaster.cpp


注:本文中的Filter::DeSamping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。