region_detect.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "../tool/point2D_tool.h"
  40. #include "../tool/common_data.h"
  41. /**
  42. * 万集区域检测算法类
  43. * */
  44. class Region_detector
  45. {
  46. public:
  47. // 有参构造函数
  48. Region_detector();
  49. // 析构函数
  50. ~Region_detector();
  51. Error_manager init(Point2D_tool::Point2D_box point2D_box);
  52. // 检测传入点云,识别为四类返回中心点、角度、轮距与宽度
  53. Error_manager detect(std::mutex* p_cloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud_in,
  54. Common_data::Car_wheel_information& car_wheel_information, bool print=true);
  55. //通过ceres检测中心,旋转,轴距,宽度, 新算法, 可以测量前轮旋转
  56. Error_manager detect_ex(std::mutex* p_cloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud_in,
  57. Common_data::Car_wheel_information& car_wheel_information, bool print=false);
  58. protected:
  59. // 预处理,直通滤波限制点云范围
  60. Error_manager preprocess(pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud);
  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. double distance(cv::Point2f p1, cv::Point2f p2);
  70. protected:
  71. Point2D_tool::Point2D_box m_region_box; // 区域范围参数
  72. detect_wheel_ceres m_detector_ceres; //ceres优化对象
  73. };
  74. #endif //REGION_DETECT_H