detect_wheel_ceres3d.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Created by zx on 2020/7/1.
  3. //
  4. #ifndef DETECT_WHEEL_CERES_3D_H
  5. #define DETECT_WHEEL_CERES_3D_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 "boost/format.hpp"
  16. #include "hybrid_grid.hpp"
  17. class detect_wheel_ceres3d {
  18. public:
  19. struct Loss_result
  20. {
  21. public:
  22. double lf_loss;
  23. double rf_loss;
  24. double lb_loss;
  25. double rb_loss;
  26. double total_avg_loss;
  27. Loss_result& operator=(const Loss_result& loss_result)
  28. {
  29. this->lf_loss = loss_result.lf_loss;
  30. this->rf_loss = loss_result.rf_loss;
  31. this->lb_loss = loss_result.lb_loss;
  32. this->rb_loss = loss_result.rb_loss;
  33. this->total_avg_loss = loss_result.total_avg_loss;
  34. return *this;
  35. }
  36. };
  37. struct Detect_result
  38. {
  39. public:
  40. double cx;
  41. double cy;
  42. double theta;
  43. double wheel_base;
  44. double width;
  45. double body_width;
  46. double front_theta;
  47. bool success;
  48. Loss_result loss;
  49. Detect_result& operator=(const Detect_result& detect_result)
  50. {
  51. this->cx = detect_result.cx;
  52. this->cy = detect_result.cy;
  53. this->theta = detect_result.theta;
  54. this->wheel_base = detect_result.wheel_base;
  55. this->width = detect_result.width;
  56. this->front_theta = detect_result.front_theta;
  57. this->success = detect_result.success;
  58. this->body_width=detect_result.body_width;
  59. this->loss=detect_result.loss;
  60. return *this;
  61. }
  62. std::string to_string()
  63. {
  64. char buf[512];
  65. sprintf(buf, "cx:%.3f cy:%.3f th:%.3f wb:%.3f wd:%.3f fth:%.3f suc:%s\n", cx, cy, theta, wheel_base, width, front_theta, success ? "true" : "false");
  66. return std::string(buf);
  67. }
  68. };
  69. detect_wheel_ceres3d(pcl::PointCloud<pcl::PointXYZ>::Ptr left_grid_cloud,
  70. pcl::PointCloud<pcl::PointXYZ>::Ptr right_grid_cloud);
  71. ~detect_wheel_ceres3d();
  72. bool detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> cloud_vec, Detect_result &detect_result, std::string &error_info);
  73. void save_debug_data(std::string file );
  74. protected:
  75. void save_model(std::string file);
  76. bool Solve(Detect_result &detect_result, Loss_result &loss_result, std::string &error_info);
  77. void get_costs(double* variable,double &lf, double &rf, double &lr, double &rr);
  78. public:
  79. pcl::PointCloud<pcl::PointXYZ> m_left_front_transformed_cloud; //左前点云
  80. pcl::PointCloud<pcl::PointXYZ> m_right_front_transformed_cloud; //右前点云
  81. pcl::PointCloud<pcl::PointXYZ> m_left_rear_transformed_cloud; //左后点云
  82. pcl::PointCloud<pcl::PointXYZ> m_right_rear_transformed_cloud; //右后点云
  83. pcl::PointCloud<pcl::PointXYZ> m_left_front_cloud; //左前点云
  84. pcl::PointCloud<pcl::PointXYZ> m_right_front_cloud; //右前点云
  85. pcl::PointCloud<pcl::PointXYZ> m_left_rear_cloud; //左后点云
  86. pcl::PointCloud<pcl::PointXYZ> m_right_rear_cloud; //右后点云
  87. private:
  88. HybridGrid* mp_left_grid;
  89. HybridGrid* mp_right_grid;
  90. };
  91. #endif //DETECT_WHEEL_CERES_3D_H