cnn3d_segmentation.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef __3DCNN__LOCATER__HH_
  2. #define __3DCNN__LOCATER__HH_
  3. #include "opencv/highgui.h"
  4. #include "opencv2/opencv.hpp"
  5. #include <pcl/point_types.h>
  6. #include <pcl/common/common.h>
  7. #include <string>
  8. #include "../error_code/error_code.h"
  9. #include "locate_manager_task.h"
  10. //Cnn3d 解析 车轮的数量, 默认为4个轮胎
  11. #define CNN3D_WHEEL_NUMBER 4
  12. //3dcnn网络解析轮胎点
  13. class Cnn3d_segmentation
  14. {
  15. public:
  16. Cnn3d_segmentation(int l,int w,int h,int freq,int nClass);
  17. //设置3dcnn网络参数
  18. Error_manager set_parameter(int l, int w, int h,int freq,int classes);
  19. virtual ~Cnn3d_segmentation();
  20. //初始化网络参数
  21. //weights:参数文件
  22. virtual Error_manager init(std::string weights);
  23. //解析4个轮胎
  24. virtual Error_manager analytic_wheel(std::map<int,pcl::PointCloud<pcl::PointXYZRGB>::Ptr>& wheel_cloud_map, bool cloud_aggregation_flag,
  25. Locate_information* p_locate_information,
  26. bool save_flag, std::string save_dir);
  27. protected:
  28. //过滤离群点,
  29. Error_manager filter_cloud_with_outlier_for_map(std::map<int,pcl::PointCloud<pcl::PointXYZRGB>::Ptr>& wheel_cloud_map);
  30. //过滤离群点,
  31. Error_manager filter_cloud_with_outlier(pcl::PointCloud<pcl::PointXYZRGB>::Ptr p_cloud);
  32. //拆分车轮, 将map分为4个轮胎
  33. //wheel_cloud_map, 输入点云
  34. //cloud_out_vector, 输出4轮点云vector, (vector是空的, 函数内部会添加4个点云)
  35. Error_manager split_wheel_cloud(std::map<int,pcl::PointCloud<pcl::PointXYZRGB>::Ptr>& wheel_cloud_map, bool cloud_aggregation_flag,
  36. std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & wheel_cloud_vector,
  37. bool save_flag, std::string save_dir);
  38. //聚类, 将一个车轮点云拆分为4个轮胎点云,
  39. //p_cloud_in, 输入点云
  40. //cloud_out_vector, 输出4轮点云vector, (vector是空的, 函数内部会添加4个点云)
  41. Error_manager split_cloud_with_kmeans(pcl::PointCloud<pcl::PointXYZRGB>::Ptr p_cloud_in,
  42. std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & cloud_out_vector,
  43. bool save_flag, std::string save_dir);
  44. //pca, 使用pca算法对每个车轮的点云进行过滤,
  45. Error_manager filter_cloud_with_pca(std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & cloud_in_vector,
  46. std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & cloud_out_vector,
  47. bool save_flag, std::string save_dir);
  48. //对点云作pca分析,然后在最小轴方向过滤, 防止轮胎左右两边出现噪声
  49. Error_manager pca_minist_axis_filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr p_cloud_in,
  50. pcl::PointCloud<pcl::PointXYZRGB>::Ptr p_cloud_out);
  51. //提取关键矩形,
  52. //cloud_in_vector, 输入点云
  53. //rect_of_wheel_center, 输出4轮中心点构成的矩形
  54. //rect_of_wheel_cloud, 输出所有车轮点构成的矩形
  55. Error_manager extract_key_rect(std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & cloud_in_vector,
  56. cv::RotatedRect & rect_of_wheel_center, cv::RotatedRect & rect_of_wheel_cloud,
  57. bool save_flag, std::string save_dir);
  58. //检查并修复关键点, 此时可以通过3个轮胎模拟出第四个轮胎的中心点位置,
  59. Error_manager check_and_repair_center(std::vector<cv::Point2f> & cloud_centers);
  60. //判断矩形框是否找到
  61. //points:输入轮子中心点, 只能是3或者4个
  62. Error_manager centers_is_rect(std::vector<cv::Point2f>& points);
  63. //检查矩形的大小
  64. Error_manager check_rect_size(cv::RotatedRect& rect);
  65. //通过关键矩形, 计算出车辆的定位信息, (输出中心点的x和y, 前后轮距, 左右轮距, 旋转角)
  66. Error_manager calculate_key_rect(cv::RotatedRect & rect_of_wheel_center, cv::RotatedRect & rect_of_wheel_cloud,
  67. Locate_information* p_locate_information);
  68. //计算两点距离
  69. static double distance(cv::Point2f p1, cv::Point2f p2);
  70. protected:
  71. int m_lenth;
  72. int m_width;
  73. int m_height;
  74. int m_freq;
  75. int m_nClass;
  76. };
  77. #endif