点云技术相关产学研社区

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

扫一扫,访问微社区

查看: 4798|回复: 1

Ubuntu上运行很慢

[复制链接]
发表于 2018-1-19 14:21:45 | 显示全部楼层 |阅读模式
想问问有没有在Ubuntu上跑的,我在Windows上跑100ms一帧的处理点云,在Ubuntu需要十几秒一帧。
是只有我一个出现这种情况吗,大家在Ubuntu的速度有理想的速度吗,大概多快。

这是我在Ubuntu上运行一帧十几秒的代码,和Windows上的是一样的。

#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/openni2_grabber.h>
#include <pcl/common/impl/io.hpp>  
#include <pcl/point_types.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/features/moment_of_inertia_estimation.h>
#include <vector>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/impl/point_types.hpp>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/time.h>
#include <pcl/surface/impl/mls.hpp>
#include <pcl/surface/mls.h>
#include <pcl/kdtree/kdtree_flann.h>


#include <iostream>


#include <string.h>




typedef pcl::PointXYZ PointT;


pcl::PassThrough<PointT> pass;                         //直通滤波对象
pcl::VoxelGrid<PointT> sor;


pcl::NormalEstimationOMP<PointT, pcl::Normal> ne;        //法线估计对象
pcl::IntegralImageNormalEstimation<PointT, pcl::Normal> ne1;
pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; //分割对象
pcl::ExtractIndices<PointT> extract;                   //点提取对象
pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>());
pcl::EuclideanClusterExtraction<PointT> ec;


pcl::PointCloud<PointT>::Ptr cloud_filtered(new pcl::PointCloud<PointT>);
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
pcl::ModelCoefficients::Ptr coefficients_cylinder(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers_cylinder(new pcl::PointIndices);


//pcl::PointCloud<PointT>::Ptr cloud_plane(new pcl::PointCloud<PointT>());
  pcl::console::TicToc tt;


char data[8];
short x, z=0.5;




class SimpleOpenNIViewer
{
public:
  SimpleOpenNIViewer() : viewer("PCL OpenNI Viewer") {}  // Construct a cloud viewer, with a window name
  float z_min = 0.265;




  // 定义回调函数cloud_cb_,获取到数据时对数据进行处理
  void cloud_cb_(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
  {
    if (!viewer.wasStopped())
    {
      std::cerr << "Loading...\n", tt.tic();
      int times = 0;
      // Build a passthrough filter to remove spurious NaNs


      pass.setInputCloud(cloud);
      pass.setFilterFieldName("y");
      pass.setFilterLimits(-0.15, 0.15);
      pass.filter(*cloud_filtered);
      
      sor.setInputCloud(cloud_filtered);
      sor.setLeafSize(0.004f, 0.008f, 0.005f);
      sor.filter(*cloud_filtered);
      std::cerr << "PointCloud after filtering has: " << cloud_filtered->points.size() << " data points." << std::endl;
      
      tree->setInputCloud(cloud_filtered);


      std::vector<pcl::PointIndices> cluster_indices;
      ec.setClusterTolerance(0.03); // 3cm
      ec.setMinClusterSize(200);
      ec.setMaxClusterSize(1200);
      ec.setSearchMethod(tree);
      ec.setInputCloud(cloud_filtered);
      ec.extract(cluster_indices);


      pcl::PointCloud<pcl::PointXYZ>::Ptr all_cloud_cluster(new pcl::PointCloud<pcl::PointXYZ>);
      all_cloud_cluster->resize(cloud_filtered->size());
      for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin(); it != cluster_indices.end(); ++it)
      {
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster(new pcl::PointCloud<pcl::PointXYZ>);
        for (std::vector<int>::const_iterator pit = it->indices.begin(); pit != it->indices.end(); ++pit)
          cloud_cluster->points.push_back(cloud_filtered->points[*pit]);
        cloud_cluster->width = cloud_cluster->points.size();
        cloud_cluster->height = 1;
        cloud_cluster->is_dense = true;


        pcl::MomentOfInertiaEstimation <pcl::PointXYZ> feature_extractor;
        feature_extractor.setInputCloud(cloud_cluster);
        feature_extractor.compute();


        pcl::PointXYZ min_point_AABB;
        pcl::PointXYZ max_point_AABB;
        feature_extractor.getAABB(min_point_AABB, max_point_AABB);
        
        if (z > 0.33)z_min = 0.285;
        else z_min = 0.26;
        if (((max_point_AABB.x- min_point_AABB.x)<0.1)&& ((max_point_AABB.z - min_point_AABB.z)<0.13)&& ((max_point_AABB.y - min_point_AABB.y)>z_min))
        {
          all_cloud_cluster->operator+=(*cloud_cluster);
          times++;
          x = ((max_point_AABB.x + min_point_AABB.x) / 2)*1000;
          z = min_point_AABB.z*100;
          std::cout << max_point_AABB.x - min_point_AABB.x<< "  " << max_point_AABB.z - min_point_AABB.z<<"  " << max_point_AABB.y - min_point_AABB.y << std::endl;
          std::cout << (max_point_AABB.x + min_point_AABB.x) / 2 << "  " << min_point_AABB.z << std::endl;
        }
        std::cout << "PointCloud representing the Cluster: " << cloud_cluster->points.size() << " data points." << std::endl;


      }
      viewer.showCloud(all_cloud_cluster);
      std::cout << std::endl;


      if (times > 1)
      {
        x = 0;
        z = 0;
      }
      
     
      std::cerr << ">> Done: " << tt.toc() << " ms\n";
      
   
    }
  }


  void run()
  {
    // create a new grabber for OpenNI devices
    pcl::Grabber* interface = new pcl::io::OpenNI2Grabber();


    // make callback function from member function
    boost::function<void(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
      boost::bind(&SimpleOpenNIViewer::cloud_cb_, this, _1);


    // connect callback function for desired signal
    boost::signals2::connection c = interface->registerCallback(f);


    // start receiving point clouds
    interface->start();


    while (!viewer.wasStopped())
    {
      boost::this_thread::sleep(boost::posix_time::seconds(1));
    }


    // Stop the data acquisition
    interface->stop();
  }


  pcl::visualization::CloudViewer viewer;
};




int main()
{
  data[5] = 0;
  data[6] = 0;
  data[7] = 0x5A;
  //Sleep(10000);
  SimpleOpenNIViewer v;


  v.run();


  return 0;
}


回复

使用道具 举报

发表于 2018-5-1 18:08:20 | 显示全部楼层
同关心。ubuntu的开发效率
回复 支持 反对

使用道具 举报

本版积分规则

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

GMT+8, 2024-4-24 03:36 , Processed in 1.670962 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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