线性插值

  1. // /home/hcq/github/point_clouds_curb_detection/ws_curb/src/CurbDetection/src/cluster_polygon.cpp
  2. void ClusterPolygon::connectPolygon(PointCloudType::Ptr bound, PointCloudType::Ptr edge){
  3. bound->points.push_back(bound->points[0]); // 最后添加一个点,其实用不到,只是为了后面循环最后一个数的时候,防止p2为空
  4. float resolution = 0.2f; // 分辨率
  5. int iten = 0;
  6. for(int i = 0; i < static_cast<int>(bound->points.size()) - 1; i++){
  7. PointT p1 = bound->points[i];
  8. PointT p2 = bound->points[i + 1];
  9. if(i == 0){
  10. iten++;
  11. p1.intensity = iten;
  12. edge->points.push_back(p1); // 保存在edge中
  13. }
  14. float dis = sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2)); // 两点距离
  15. int insertNum = ceil(dis / resolution); // 取整函数ceil(),floor()
  16. for(int m = insertNum; m >= 1; m--){
  17. iten++;
  18. PointT addPt; // m=1的时候是自身
  19. addPt.x = (m * p1.x + (insertNum + 1 - m) * p2.x) / (insertNum + 1);
  20. addPt.y = (m * p1.y + (insertNum + 1 - m) * p2.y) / (insertNum + 1);
  21. addPt.z = (m * p1.z + (insertNum + 1 - m) * p2.z) / (insertNum + 1);
  22. addPt.intensity = iten;
  23. edge->points.push_back(addPt);// 保存在edge中
  24. }
  25. if(i != static_cast<int>(bound->points.size()) - 2){ // ???????当i = (points.size()) - 2) p2这一点是(bound->points[0]
  26. iten++;
  27. p2.intensity = iten;
  28. edge->points.push_back(p2); //
  29. }
  30. }
  31. }

PCA利用PCA主元分析法获得点云的三个主方向,获取质心,计算协方差,获得协方差矩阵,求取协方差矩阵的特征值和特长向量,特征向量即为主方向。

https://blog.csdn.net/u013541523/article/details/82982522?
https://blog.csdn.net/WillWinston/article/details/80196895

使用vector存储三维点云

https://blog.csdn.net/lch_vison/article/details/80691428?
https://blog.csdn.net/GIS_feifei/article/details/97894371

利用pcl进行点云索引提取时,经常需要迭代分割提取多块子点云,为了方便存储管理,通常使用向量来进行。这时有两种思路存储分割后的子点云:

  • 一种是将子点云的索引存入向量
  • 另一种是将点云存入向量

    1. 需要的注意的是,如果将子点云的索引存入向量,容易出现问题:循环迭代的输入点云发生了变化,所以得到的子点云索引是新输入点云中的索引,并非最初的输入点云的索引。所以,**最可靠的方法是将子点云存入向量。这时关于点云向量的定义如下:**

    ```cpp std::vector, Eigen::aligned_allocator > clouds_vector;

clouds_vector.push_back(cloud); //将点云存入点云向量。

  1. <a name="sffpN"></a>
  2. ### 遍历点云
  3. ```cpp
  4. PointCloudType::Ptr transformedCloud = boost::make_shared<PointCloudType>();
  5. for(auto &pt:transformedCloud->points){
  6. pt.intensity = 0;
  7. pt.x = pt.z; //
  8. }

1 每帧点云数据记得清空clear()

  1. if (!featVec.empty())
  2. featVec.clear();

2 同步问题

双线程同步

https://developer.aliyun.com/article/584964
https://www.shuangyi-tech.com/news_188.html

  1. /*
  2. * @Description: 双线程时间同步 https://www.shuangyi-tech.com/news_188.html
  3. 运行命令:cd "/home/hcq/github/c-plus-plus/practice/01时间同步/" && g++ 01time_sync.cpp -o 01time_sync -pthread && "/home/hcq/github/c-plus-plus/practice/01时间同步/"01time_sync
  4. * @Author: HCQ
  5. * @Company(School): UCAS
  6. * @Email: 1756260160@qq.com
  7. * @Date: 2021-04-15 10:56:25
  8. * @LastEditTime: 2021-04-15 11:05:22
  9. * @FilePath: /c-plus-plus/practice/01时间同步/01time_sync.cpp
  10. */
  11. #include <iostream>
  12. #include <thread>
  13. #include <mutex>
  14. #include <vector>
  15. #include <condition_variable>
  16. using namespace std;
  17. std::mutex mtx;
  18. std::condition_variable cv;
  19. std::vector<int> vec;
  20. int productNum = 5;
  21. void Producer()
  22. {
  23. for (int i = 1; i <= productNum; ++i) {
  24. std::unique_lock<std::mutex> lock(mtx);
  25. while (!vec.empty()) {
  26. cv.wait(lock); // vec 不为空时阻塞当前线程
  27. }
  28. vec.push_back(i);
  29. std::cout << "Producer生产产品: " << i << std::endl;
  30. cv.notify_all(); // 释放线程锁
  31. }
  32. }
  33. void Consumer()
  34. {
  35. while (true) {
  36. std::unique_lock<std::mutex> lock(mtx);
  37. while (vec.empty()) {
  38. cv.wait(lock); // vec 为空时等待线程锁。其他线程锁释放时,当前线程继续执行
  39. }
  40. int data = vec.back();
  41. vec.pop_back();
  42. std::cout << "Consumer消费产品: " << data << std::endl;
  43. cv.notify_all();
  44. }
  45. }
  46. int main()
  47. {
  48. std::thread t1(Producer);
  49. std::thread t2(Consumer);
  50. t2.join();
  51. t1.join();
  52. std::cin.get();
  53. }

运行命令
cd “/home/hcq/github/c-plus-plus/practice/01时间同步/“ && g++ 01time_sync.cpp -o 01time_sync -pthread && “/home/hcq/github/c-plus-plus/practice/01时间同步/“01time_sync

PCL项目细节记录(个人) - 图1

获取时间戳同步

IMG_20210415_102523.jpg

3 查看点云中label==1个数

  1. // 查看点云中label==1个数
  2. int number=0;
  3. for (int i = 0; i < cloud.size(); i++) {
  4. if(cloud.points[i].label ){
  5. number++;
  6. }
  7. }
  8. std::cout <<"======number:" << number<<"======总数:" << cloud.size()<< std::endl; // 输出

pcl::compute3DCentroid& pcl::getMinMax3D

/home/hcq/github/point_clouds_curb_detection/ws_curb/src/CurbDetection/src/curb_detection.cpp

  1. pcl::compute3DCentroid (cloud_cluster, centroid); // 坐标 centroid- 重心 / /计算点云中心
  2. pcl::getMinMax3D (cloud_cluster, min, max); // 输出min_pt为所有点中最小的x值,y值,z值,输出max_pt为为所有点中最大的x值,y值,z值。
  3. //1 pcl::compute3D计算点云中心
  4. Eigen::Vector4f centroid;
  5. pcl::compute3DCentroid(*cloud, centroid);
  6. // cout << "点云质心("
  7. // << centroid[0] << ","
  8. // << centroid[1] << ","
  9. // << centroid[2] << ")." << endl;
  10. //2 pcl::getMinMax3D 得到它x,y,z三个轴上的最大值和最小值

pcl::compute3DCentroid()计算质心算法原理
点云的质心是一个点,其坐标是通过计算云中所有点的值的平均值得出的。可以说它是“质量中心
PCL_Tutorial2-1.8-计算点云质心

pcl::getMinMax3D 计算点云轴向最值

https://blog.csdn.net/qq_36501182/article/details/79005933
有一个点云,想得到它x,y,z三个轴上的最大值和最小值。可以用pcl::getMinMax3D函数。
函数参数:1:点云,2:放最小值的容器,3:放最大值的容器。容器类型是点云中点的类型(正好有三个值)
即cloud为输入点云,而非指针(共享指针则写为cloud),输出min_pt为所有点中最小的x值,y值,z值,输出max_pt为为所有点中最大的x值,y值,z值。
*Parameters:

cloud the point cloud data message
indices the vector of point indices to use from cloud
min_pt the resultant minimum bounds
max_pt the resultant maximum bounds
  1. pcl::getMinMax3D(*pcd, min_point, max_point); // 得到最大点和最小点
  2. x_min_ = min_point.x;
  3. y_min_ = min_point.y;
  4. float x_max = max_point.x;
  5. float y_max = max_point.y;

pcl::computeCovarianceMatrixNormalized

https://blog.csdn.net/u013541523/article/details/82982522?
计算最小包围框

pcl::transformPointCloud(clusterPtr[i], transformedCloud, transform)

使用创建的变换对输入点云进行变换

pcl计算最小包围框

https://blog.csdn.net/u013541523/article/details/82982522?
计算最小包围框

PCL ——最小包围盒(画出了最小包围盒并求出顶点坐标…
计算点云的最小BBOX
PCL_PCA-最小包围盒(画出最小包围盒顶点)
点云处理—-最小矩形包围盒
PCL中点云BoundingBox包围盒绘制(基于PCA)