wheel_detector.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "tool/singleton.hpp"
  3. #include <algorithm>
  4. #include <pcl/point_cloud.h>
  5. #include <pcl/point_types.h>
  6. #include <pcl/filters/passthrough.h>
  7. #include <pcl/filters/statistical_outlier_removal.h>
  8. #include <pcl/common/transforms.h>
  9. #include <pcl/visualization/pcl_visualizer.h>
  10. #include "tool/point3D_tool.hpp"
  11. class WheelCeresDetector : public Singleton<WheelCeresDetector> {
  12. friend class Singleton<WheelCeresDetector>;
  13. public:
  14. struct WheelDetectResult {
  15. bool haveCloud = false;
  16. bool segmentOk = false;
  17. bool detectOk = false;
  18. bool detectOkOnTime = false;
  19. pcl::PointXYZ center;
  20. float confidence = 0;
  21. float theta = 0;
  22. float loss = 0;
  23. void reset() {
  24. haveCloud = false;
  25. segmentOk = false;
  26. detectOk = false;
  27. detectOkOnTime = false;
  28. center.x = 0;
  29. center.y = 0;
  30. center.z = 0;
  31. confidence = 0;
  32. theta = 0;
  33. loss = 0;
  34. }
  35. std::string info() {
  36. char str[512];
  37. sprintf(str, "x: %.3f, y: %.3f, z: %.3f, theta: %.3f loss: %.3f conf: %.3f\n",
  38. center.x, center.y, center.z, theta, loss, confidence);
  39. return str;
  40. }
  41. };
  42. WheelCeresDetector &operator=(const WheelCeresDetector &) = delete;
  43. ~WheelCeresDetector() override = default;
  44. // 单轮检测
  45. bool detect(pcl::PointCloud<pcl::PointXYZ>::Ptr in_cloud_ptr, pcl::PointCloud<pcl::PointXYZ>::Ptr out_cloud_ptr,
  46. WheelDetectResult &result, bool left_model);
  47. bool detect(pcl::PointCloud<pcl::PointXYZ>::Ptr left_in_cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr left_out_cloud,
  48. WheelDetectResult &left_result,
  49. pcl::PointCloud<pcl::PointXYZ>::Ptr right_in_cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr right_out_cloud,
  50. WheelDetectResult &right_result);
  51. bool detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> vct_wheels_cloud,
  52. pcl::PointCloud<pcl::PointXYZ>::Ptr left_out_cloud,
  53. WheelCeresDetector::WheelDetectResult *wheels_result);
  54. protected:
  55. // 父类的构造函数必须保护,子类的构造函数必须私有。
  56. WheelCeresDetector() = default;
  57. private:
  58. std::vector<float> singleWheelModel();
  59. std::vector<float> singleLeftWheelModel();
  60. std::vector<float> singleRightWheelModel();
  61. void doubleWheelModel( std::vector<float>& linel,std::vector<float>& liner);
  62. private:
  63. std::vector<double> line_;
  64. };