zoukankan      html  css  js  c++  java
  • 利用三维模型生成点云总结

    在做三维的深度学习时,可以利用已有的CAD模型得到点云数据

    1.利用pcl库

    pcl库中有多个函数可以实现模型的读入和点云的生成。
    I/O模块下有三个函数可以载入数据:

    pcl::io::loadPCDFile()
    pcl::io::loadOBJFile()
    pcl::io::loadPLYFile()
    

    同时tools模块下就包含了两个转换函数obj2pcdply2pcd
    其中obj2pcd的实现代码如下:

    int
    main (int argc, char** argv)
    {
      print_info ("Convert a OBJ file to PCD format. For more information, use: %s -h
    ", argv[0]);
    
      if (argc < 3)
      {
        printHelp (argc, argv);
        return (-1);
      }
    
      // Parse the command line arguments for .pcd and .obj files
      std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
      std::vector<int> obj_file_indices = parse_file_extension_argument (argc, argv, ".obj");
      if (pcd_file_indices.size () != 1 || obj_file_indices.size () != 1)
      {
        print_error ("Need one input OBJ file and one output PCD file.
    ");
        return (-1);
      }
    
      // Load the OBJ file
      TicToc tt;
      print_highlight ("Loading "); print_value ("%s ", argv[obj_file_indices[0]]);
    
      // Load the input file
      vtkSmartPointer<vtkPolyData> polydata;
      vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New ();
      reader->SetFileName (argv[obj_file_indices[0]]);
      reader->Update ();
      polydata = reader->GetOutput ();
      print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", polydata->GetNumberOfPoints ()); print_info (" points]
    ");
    
      bool copy_normals = false;
      parse_argument (argc, argv, "-copy_normals", copy_normals);
      PCL_INFO ("Copy normals: %s.
    ", copy_normals ? "true" : "false");
    
      if (copy_normals)
      {
        vtkSmartPointer<vtkPolyDataNormals> ng = vtkSmartPointer<vtkPolyDataNormals>::New ();
    #if VTK_MAJOR_VERSION < 6
        ng->SetInput (polydata);
    #else
        ng->SetInputData (polydata);
    #endif
        ng->ComputePointNormalsOn ();
        ng->ComputeCellNormalsOff ();
        ng->Update ();
        polydata = ng->GetOutput ();
    
        pcl::PointCloud<pcl::PointNormal> cloud;
        vtkPolyDataToPointCloud (polydata, cloud);
        // Convert to pcd and save
        saveCloud (argv[pcd_file_indices[0]], cloud);
      }
      else
      { 
        pcl::PointCloud<pcl::PointXYZ> cloud;
        vtkPolyDataToPointCloud (polydata, cloud);
        // Convert to pcd and save
        saveCloud (argv[pcd_file_indices[0]], cloud);
      }
    
      return (0);
    }
    

    ply2pcd代码实现如下:

    //https://github.com/PointCloudLibrary/pcl/tree/master/tools
    int
    main (int argc, char** argv)
    {
      print_info ("Convert a PLY file to PCD format. For more information, use: %s -h
    ", argv[0]);
    
      if (argc < 3)
      {
        printHelp (argc, argv);
        return (-1);
      }
    
      // Parse the command line arguments for .pcd and .ply files
      std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
      std::vector<int> ply_file_indices = parse_file_extension_argument (argc, argv, ".ply");
      if (pcd_file_indices.size () != 1 || ply_file_indices.size () != 1)
      {
        print_error ("Need one input PLY file and one output PCD file.
    ");
        return (-1);
      }
    
      // Command line parsing
      bool format = 1;
      parse_argument (argc, argv, "-format", format);
      print_info ("PCD output format: "); print_value ("%s
    ", (format ? "binary" : "ascii"));
    
      // Load the first file
      pcl::PCLPointCloud2 cloud;
      if (!loadCloud (argv[ply_file_indices[0]], cloud)) 
        return (-1);
    
      // Convert to PLY and save
      saveCloud (argv[pcd_file_indices[0]], cloud, format);
    
      return (0);
    }
    

    2.使用深度图恢复点云

    如果在有深度图的情况下,可以使用相机的内参来获取点云数据,下面是利用pcl库的简单算法(from Dominik13993)
    tips数据集:
    华盛顿大学300个家庭常见物体
    斯坦福三维扫描数据集

    //详细解释:http://www.pcl-users.org/Getting-strange-results-when-moving-from-depth-map-to-point-cloud-tt4025104.html#a4025141
    
    //core process
    pointcloud.width = width; 
    pointcloud.height = height; 
    pointcloud.points.resize (pointcloud.height * pointcloud.width); 
    
    int* depth_data = new int[pointcloud.height * pointcloud.width]; 
    //copy the depth values of every pixel in here 
    
    register float constant = 1.0f / 525; 
    register int centerX = (pointcloud.width >> 1); 
    int centerY = (pointcloud.height >> 1); 
    register int depth_idx = 0; 
    for (int v = -centerY; v < centerY; ++v) 
    { 
            for (register int u = -centerX; u < centerX; ++u, ++depth_idx) 
            { 
                    pcl::PointXYZ& pt = pointcloud.points[depth_idx]; 
                    pt.z = depth_data[depth_idx] * 0.001f; 
                    pt.x = static_cast<float> (u) * pt.z * constant; 
                    pt.y = static_cast<float> (v) * pt.z * constant; 
            } 
    } 
    pointcloud.sensor_origin_.setZero (); 
    pointcloud.sensor_orientation_.w () = 0.0f; 
    pointcloud.sensor_orientation_.x () = 1.0f; 
    pointcloud.sensor_orientation_.y () = 0.0f; 
    pointcloud.sensor_orientation_.z () = 0.0f; 
    

    3.利用渲染工具

    TODO from Sharon

    4.点云数据库

    参考:三维点云数据集总结

    在这里插入图片描述
    icon from easyicon


    ref:
    pcl:http://pointclouds.org/documentation/
    pcl.cn:http://www.pclcn.org
    zhihu:https://www.zhihu.com/question/37577447

  • 相关阅读:
    weblogic详解
    Java实现视频网站的视频上传、视频转码、及视频播放功能(ffmpeg)
    Java上传视频(mencoder)
    input标签type="file"上传文件的css样式
    jQuery系列:选择器
    jQuery系列:Ajax
    Sql Server系列:规范化及基本设计
    Sql Server系列:查询分页语句
    Sql Server系列:通用表表达式CTE
    Sql Server系列:子查询
  • 原文地址:https://www.cnblogs.com/Tom-Ren/p/10024300.html
Copyright © 2011-2022 走看看