chassis_ceres_solver.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Created by zx on 2021/9/17.
  3. //
  4. #ifndef FIND_CHASSIS__CHASSIS_CERES_SOLVER_H_
  5. #define FIND_CHASSIS__CHASSIS_CERES_SOLVER_H_
  6. #include <ceres/ceres.h>
  7. #include <glog/logging.h>
  8. #include <pcl/point_types.h>
  9. #include <pcl/point_cloud.h>
  10. #include <pcl/common/centroid.h>
  11. #include <opencv2/opencv.hpp>
  12. #include <iostream>
  13. #include <string>
  14. #include <chrono>
  15. #include "../error_code/error_code.h"
  16. constexpr float kMinProbability = 0.01f;
  17. constexpr float kMaxProbability = 1.f - kMinProbability;
  18. constexpr float kMaxCorrespondenceCost = 1.f - kMinProbability;
  19. constexpr int kPadding = INT_MAX / 4;
  20. constexpr float resolutionx = 0.01;
  21. constexpr float resolutiony = 0.005;
  22. constexpr float inner_width = 1.2;
  23. constexpr float chassis_height = 0.14;
  24. constexpr float startx = -2.0;
  25. constexpr float starty = -0.1;
  26. constexpr float endx = 2.0;
  27. constexpr float endy = 0.3;
  28. class chassis_ceres_solver
  29. {
  30. public:
  31. chassis_ceres_solver();
  32. ~chassis_ceres_solver();
  33. Error_manager solve(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,double& x,double& z,double& w,double& h);
  34. // 利用图像优化,计算速度提升
  35. Error_manager solve_mat(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,double& x,double& z,double& w,double& h, bool update_debug_img=false);
  36. // 创建优化地图
  37. static cv::Mat create_mat();
  38. // 返回更新投影地图
  39. cv::Mat get_projected_mat() { return m_projected_mat; }
  40. // 返回投影地图转换的点云, 便于投影到pcl视野中
  41. pcl::PointCloud<pcl::PointXYZ>::Ptr get_projected_cloud()
  42. {
  43. pcl::PointCloud<pcl::PointXYZ>::Ptr t_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  44. if (m_projected_mat.empty())
  45. return t_cloud;
  46. for (size_t i = 0; i < m_projected_mat.rows; i++)
  47. {
  48. for (size_t j = 0; j < m_projected_mat.cols; j++)
  49. {
  50. double x0 = (i * resolutionx + startx);
  51. t_cloud->push_back(pcl::PointXYZ());
  52. }
  53. }
  54. return t_cloud;
  55. }
  56. private:
  57. static cv::Mat m_model;
  58. cv::Mat m_projected_mat;
  59. };
  60. #endif //FIND_CHASSIS__CHASSIS_CERES_SOLVER_H_