#ifndef __3DCNN__LOCATER__HH_ #define __3DCNN__LOCATER__HH_ #include "opencv/highgui.h" #include "opencv2/opencv.hpp" #include #include #include #include "../error_code/error_code.h" #include "locate_manager_task.h" //Cnn3d 解析 车轮的数量, 默认为4个轮胎 #define CNN3D_WHEEL_NUMBER 4 //3dcnn网络解析轮胎点 class Cnn3d_segmentation { public: Cnn3d_segmentation(int l,int w,int h,int freq,int nClass); //设置3dcnn网络参数 Error_manager set_parameter(int l, int w, int h,int freq,int classes); virtual ~Cnn3d_segmentation(); //初始化网络参数 //weights:参数文件 virtual Error_manager init(std::string weights); //解析4个轮胎 virtual Error_manager analytic_wheel(std::map::Ptr>& wheel_cloud_map, bool cloud_aggregation_flag, Locate_information* p_locate_information, bool save_flag, std::string save_dir); protected: //过滤离群点, Error_manager filter_cloud_with_outlier_for_map(std::map::Ptr>& wheel_cloud_map); //过滤离群点, Error_manager filter_cloud_with_outlier(pcl::PointCloud::Ptr p_cloud); //拆分车轮, 将map分为4个轮胎 //wheel_cloud_map, 输入点云 //cloud_out_vector, 输出4轮点云vector, (vector是空的, 函数内部会添加4个点云) Error_manager split_wheel_cloud(std::map::Ptr>& wheel_cloud_map, bool cloud_aggregation_flag, std::vector::Ptr> & wheel_cloud_vector, bool save_flag, std::string save_dir); //聚类, 将一个车轮点云拆分为4个轮胎点云, //p_cloud_in, 输入点云 //cloud_out_vector, 输出4轮点云vector, (vector是空的, 函数内部会添加4个点云) Error_manager split_cloud_with_kmeans(pcl::PointCloud::Ptr p_cloud_in, std::vector::Ptr> & cloud_out_vector, bool save_flag, std::string save_dir); //pca, 使用pca算法对每个车轮的点云进行过滤, Error_manager filter_cloud_with_pca(std::vector::Ptr> & cloud_in_vector, std::vector::Ptr> & cloud_out_vector, bool save_flag, std::string save_dir); //对点云作pca分析,然后在最小轴方向过滤, 防止轮胎左右两边出现噪声 Error_manager pca_minist_axis_filter(pcl::PointCloud::Ptr p_cloud_in, pcl::PointCloud::Ptr p_cloud_out); //提取关键矩形, //cloud_in_vector, 输入点云 //rect_of_wheel_center, 输出4轮中心点构成的矩形 //rect_of_wheel_cloud, 输出所有车轮点构成的矩形 Error_manager extract_key_rect(std::vector::Ptr> & cloud_in_vector, cv::RotatedRect & rect_of_wheel_center, cv::RotatedRect & rect_of_wheel_cloud, bool save_flag, std::string save_dir); //检查并修复关键点, 此时可以通过3个轮胎模拟出第四个轮胎的中心点位置, Error_manager check_and_repair_center(std::vector & cloud_centers); //判断矩形框是否找到 //points:输入轮子中心点, 只能是3或者4个 Error_manager centers_is_rect(std::vector& points); //检查矩形的大小 Error_manager check_rect_size(cv::RotatedRect& rect); //通过关键矩形, 计算出车辆的定位信息, (输出中心点的x和y, 前后轮距, 左右轮距, 旋转角) Error_manager calculate_key_rect(cv::RotatedRect & rect_of_wheel_center, cv::RotatedRect & rect_of_wheel_cloud, Locate_information* p_locate_information); //计算两点距离 static double distance(cv::Point2f p1, cv::Point2f p2); protected: int m_lenth; int m_width; int m_height; int m_freq; int m_nClass; }; #endif