• 1.读写点云文件


    1.PCD文件读写
     

    1. #include
    2. #include
    3. #include
    4. void savePcdFun()//save pcdfile
    5. {
    6. pcl::PointCloud cloud;
    7. cloud.width = 5;
    8. cloud.height = 1;
    9. cloud.is_dense = false;
    10. cloud.points.resize(cloud.width * cloud.height);
    11. for (int i = 0; i < cloud.points.size(); ++i)
    12. {
    13. cloud.points[i].x = 1024 * rand() / (RAND_MAX + 0.1f);
    14. cloud.points[i].y = 1024 * rand() / (RAND_MAX + 0.1f);
    15. cloud.points[i].z = 1024 * rand() / (RAND_MAX + 0.1f);
    16. }
    17. pcl::io::savePCDFile("do1.pcd", cloud);
    18. return;
    19. }
    20. void loadPcdFun()//load pcdfile
    21. {
    22. pcl::PointCloud cloud;
    23. if (pcl::io::loadPCDFile("ajaccio_2 - Cloud.pcd", cloud) ==-1)
    24. {
    25. PCL_ERROR("load pcdfile failed!");
    26. }
    27. for (int i = 0; i < cloud.points.size(); ++i)
    28. {
    29. std::cout << cloud.points[i].x << " " << cloud.points[i].y
    30. << " " << cloud.points[i].z<< std::endl;
    31. }
    32. return;
    33. }
    34. }

    2.点云字段或数据连接:

    1. void concateFun()//concatenate filed
    2. {
    3. pcl::PointCloud cloud_a;
    4. if (pcl::io::loadPCDFile("do1.pcd", cloud_a) == -1)
    5. {
    6. PCL_ERROR("load pcdfile failed !");
    7. }
    8. pcl::PointCloudcloud_b_normal;
    9. cloud_b_normal.width = 5;
    10. cloud_b_normal.height = 1;
    11. cloud_b_normal.is_dense = false;
    12. cloud_b_normal.points.resize(cloud_b_normal.width * cloud_b_normal.height);
    13. for (int i = 0; i < cloud_b_normal.points.size(); ++i)
    14. {
    15. cloud_b_normal.points[i].normal[0]=1024*rand()/(RAND_MAX+1.0f);
    16. cloud_b_normal.points[i].normal[1]= 1024 * rand() / (RAND_MAX + 1.0f);
    17. cloud_b_normal.points[i].normal[2]= 1024 * rand() / (RAND_MAX + 1.0f);
    18. }
    19. pcl::PointCloudcloud_c;
    20. pcl::concatenateFields(cloud_a, cloud_b_normal, cloud_c);
    21. for (int j = 0; j < cloud_c.points.size(); ++j)
    22. {
    23. std::cout << cloud_c.points[j].x << " " << cloud_c.points[j].y
    24. << " " << cloud_c.points[j].z << " " << cloud_c.points[j].normal[0]
    25. << " " << cloud_c.points[j].normal[1] << " " << cloud_c.points[j].normal[2] <<
    26. std::endl;
    27. }

    3.基于OpenNI接口的点云数据获取

    1. #pragma
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. //读取深度信息 实时显示3d点云
    8. class SimpleOpenNIProcessor
    9. {
    10. public:
    11. pcl::visualization::CloudViewer viewer;
    12. //construct a cloud viewer,with a window name
    13. SimpleOpenNIProcessor() :viewer("pcl openni viewer")
    14. {
    15. }
    16. //定义回调函数cloub_cb_,获取到数据时对数据进行处理
    17. void cloud_cb_(const pcl::PointCloud::ConstPtr& cloud)
    18. {
    19. if (!viewer.wasStopped())
    20. {
    21. viewer.showCloud(cloud);
    22. }
    23. }
    24. void run()
    25. {
    26. //create a new grabber for OpenNI Devices
    27. pcl::Grabber* m_interface = new pcl::io::OpenNI2Grabber();
    28. //定义回调函数
    29. boost::function<void(pcl::PointCloud::ConstPtr&)> f =
    30. boost::bind(&SimpleOpenNIProcessor::cloud_cb_, this, _1);
    31. //注册回调函数
    32. boost::signals2::connection c = m_interface->registerCallback(f);
    33. //start receive cloud
    34. m_interface->start();
    35. while (!viewer.wasStopped())
    36. {
    37. boost::this_thread::sleep(boost::posix_time::seconds(1));
    38. }
    39. //stop data aquisition
    40. m_interface->stop();
    41. }
    42. };
    1. int main()
    2. {
    3. SimpleOpenNIProcessor myViewer;
    4. myViewer.run();
    5. return 0;
    6. }

  • 相关阅读:
    Linux---用户组命令(groupadd、groupdel、groupmod、newgrp、getent)
    【Spring Cloud】Gateway的配置与使用
    Cesium性能优化:高效加载billboard图标和label文字标签
    LeetCode 剑指 Offer 10- I. 斐波那契数列
    kafka创建、启动topic遇到的bug汇总 解决方法
    2.2 Linux系统的目录结构与文件类型
    【 第六章 事务操作、事务四大特性、并发事务问题、事务隔离级别】
    【C++】类和对象(中)
    搭建SGC实现引文网络节点预测(PyTorch+PyG)
    C语言练习题之函数部分
  • 原文地址:https://blog.csdn.net/m0_57747965/article/details/126108358