region_detect.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Created by zx on 2019/12/6.
  3. //
  4. #ifndef REGION_DETECT_H
  5. #define REGION_DETECT_H
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. #include <mutex>
  10. #include <vector>
  11. #include <atomic>
  12. #include "eigen3/Eigen/Core"
  13. #include "eigen3/Eigen/Dense"
  14. #include <pcl/point_types.h>
  15. #include <pcl/PCLPointCloud2.h>
  16. #include <pcl/conversions.h>
  17. #include <pcl/filters/passthrough.h>
  18. #include <pcl/filters/statistical_outlier_removal.h>
  19. #include <pcl/segmentation/extract_clusters.h>
  20. #include <pcl/common/centroid.h>
  21. #include <pcl/common/common.h>
  22. #include <boost/thread.hpp>
  23. #include <google/protobuf/io/coded_stream.h>
  24. #include <google/protobuf/io/zero_copy_stream_impl.h>
  25. #include <google/protobuf/text_format.h>
  26. using google::protobuf::io::FileInputStream;
  27. using google::protobuf::io::FileOutputStream;
  28. using google::protobuf::io::ZeroCopyInputStream;
  29. using google::protobuf::io::CodedInputStream;
  30. using google::protobuf::io::ZeroCopyOutputStream;
  31. using google::protobuf::io::CodedOutputStream;
  32. using google::protobuf::Message;
  33. #include "glog/logging.h"
  34. #include "../error_code/error_code.h"
  35. #include "wj_lidar_conf.pb.h"
  36. #include "../tool/StdCondition.h"
  37. #include "opencv2/opencv.hpp"
  38. #include "detect_wheel_ceres.h"
  39. /**
  40. * 万集区域检测算法类
  41. * */
  42. class Region_detector
  43. {
  44. public:
  45. // 有参构造函数
  46. Region_detector(int id, wj::Region region);
  47. // 析构函数
  48. ~Region_detector();
  49. // 检测传入点云是否为合法四轮
  50. Error_manager detect(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in);
  51. // 检测传入点云,识别为四类返回中心点、角度、轮距与宽度
  52. Error_manager detect(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, double &x, double &y, double &c, double &wheelbase, double &width, bool print=true);
  53. //通过ceres检测中心,旋转,轴距,宽度,前轮旋转
  54. Error_manager detect(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud_in, double &x, double &y, double &c,double& front_wheel_theta,
  55. double &wheelbase, double &width, bool print=true);
  56. // 获得区域id
  57. int get_region_id();
  58. private:
  59. // 预处理,直通滤波限制点云范围
  60. Error_manager preprocess(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out);
  61. // 点云聚类,寻找四类点云并检验是否近似矩形
  62. Error_manager clustering(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in, std::vector<cv::Point2f>& corner_points,
  63. std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> &seg_clouds, bool print=false);
  64. //仅仅聚类
  65. Error_manager clustering_only(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in,
  66. std::vector<pcl::PointCloud<pcl::PointXYZ>> &seg_clouds, bool print=false);
  67. // 判断是否足够近似矩形
  68. Error_manager isRect(std::vector<cv::Point2f>& points, bool print=false);
  69. private:
  70. wj::Region m_region_param; // 区域范围参数
  71. std::atomic<int> m_region_id; // 区域id
  72. detect_wheel_ceres m_detector_ceres; //ceres优化对象
  73. };
  74. #endif //REGION_DETECT_H