depth_sensor_pose.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <limits>
5 #include <vector>
6 #include <cmath>
7 #include <string>
8 #include <iostream>
9 #include <fstream>
10 #include <list>
11 
12 #include <ros/console.h>
13 #include <ros/ros.h>
14 
15 #include <sensor_msgs/Image.h>
16 #include <sensor_msgs/LaserScan.h>
19 
20 #include <pcl/point_types.h>
21 #include <pcl/sample_consensus/ransac.h>
22 #include <pcl/sample_consensus/sac_model_plane.h>
23 #include <pcl/sample_consensus/method_types.h>
24 #include <pcl/sample_consensus/model_types.h>
25 #include <pcl/segmentation/sac_segmentation.h>
26 
27 #include <Eigen/Core>
28 
29 namespace depth_sensor_pose {
30 
32  public:
33  DepthSensorPose() = default;
34  ~DepthSensorPose() = default;
35 
36  DepthSensorPose (const DepthSensorPose &) = delete;
37  DepthSensorPose & operator= (const DepthSensorPose &) = delete;
38 
51  void estimateParams(const sensor_msgs::ImageConstPtr& depth_msg,
52  const sensor_msgs::CameraInfoConstPtr& info_msg);
63  void setRangeLimits(const float rmin, const float rmax);
64 
70  void setSensorMountHeightMin (const float height);
76  void setSensorMountHeightMax (const float height);
81  void setSensorTiltAngleMin (const float angle);
86  void setSensorTiltAngleMax (const float angle);
91  void setPublishDepthEnable (const bool enable) { publish_depth_enable_ = enable; }
96  bool getPublishDepthEnable () const { return publish_depth_enable_; }
101  void setCamModelUpdate (const bool u) { cam_model_update_ = u; }
106  void setUsedDepthHeight(const unsigned height);
111  void setDepthImgStepRow(const int step);
116  void setDepthImgStepCol(const int step);
121  void setReconfParamsUpdated(bool updated) {reconf_serv_params_updated_ = updated; }
122 
123  void setRansacMaxIter(const unsigned u) { ransacMaxIter_ = u; }
124 
125  void setRansacDistanceThresh(const float u) { ransacDistanceThresh_ = u; }
126 
127  void setGroundMaxPoints(const unsigned u) { max_ground_points_ = u; }
128 
129  float getSensorTiltAngle() const { return tilt_angle_est_; }
130 
131  float getSensorMountHeight() const { return mount_height_est_; }
132 
133  sensor_msgs::ImageConstPtr getDbgImage() const;
134 
135  protected:
145  double lengthOfVector( const cv::Point3d& vec) const;
157  double angleBetweenRays(const cv::Point3d& ray1, const cv::Point3d& ray2) const;
166  void fieldOfView(double & min, double & max, double x1, double y1,
167  double xc, double yc, double x2, double y2 );
168 
169  void calcDeltaAngleForImgRows(double vertical_fov);
179  void calcGroundDistancesForImgRows( double mount_height, double tilt_angle,
180  std::vector<double>& distances);
181 
182  template<typename T>
183  void getGroundPoints(const sensor_msgs::ImageConstPtr& depth_msg,
184  pcl::PointCloud<pcl::PointXYZ>::Ptr& points,
185  std::list<std::pair<unsigned, unsigned>>& points_indices);
186 
187  void sensorPoseCalibration(const sensor_msgs::ImageConstPtr& depth_msg,
188  double& tilt_angle, double& height);
189 
190  sensor_msgs::ImagePtr prepareDbgImage(const sensor_msgs::ImageConstPtr& depth_msg,
191  const std::list<std::pair<unsigned, unsigned>>& ground_points_indices);
192 
193  private:
194  // ROS parameters configurated with config files or dynamic_reconfigure
195  float range_min_{0};
196  float range_max_{0};
197  float mount_height_min_{0};
198  float mount_height_max_{0};
199  float tilt_angle_min_{0};
200  float tilt_angle_max_{0};
201 
202  bool publish_depth_enable_{false};
203  bool cam_model_update_{false};
204  unsigned used_depth_height_{0};
205  unsigned depth_image_step_row_{0};
206  unsigned depth_image_step_col_{0};
207 
208  unsigned max_ground_points_{0};
209  unsigned ransacMaxIter_{0};
212 
215 
216  sensor_msgs::ImagePtr dbg_image_;
217 
218  double mount_height_est_{0};
219  double tilt_angle_est_{0};
221 
222  std::vector<double> delta_row_;
223  std::vector<double>dist_to_ground_max_;
224  std::vector<double>dist_to_ground_min_;
225 };
226 
227 } // namespace depth_sensor_pose
void getGroundPoints(const sensor_msgs::ImageConstPtr &depth_msg, pcl::PointCloud< pcl::PointXYZ >::Ptr &points, std::list< std::pair< unsigned, unsigned >> &points_indices)
void setUsedDepthHeight(const unsigned height)
setUsedDepthHeight
std::vector< double > dist_to_ground_min_
std::vector< double > dist_to_ground_max_
float mount_height_min_
Min height of sensor mount from ground.
float groundDistTolerance_
Class for managing sensor_msgs/CameraInfo messages.
float tilt_angle_min_
Min angle of sensor tilt in degrees.
image_geometry::PinholeCameraModel camera_model_
void calcGroundDistancesForImgRows(double mount_height, double tilt_angle, std::vector< double > &distances)
Calculates distances to ground for every row of depth image.
float tilt_angle_max_
Max angle of sensor tilt in degrees.
bool cam_model_update_
Determines if continuously cam model update is required.
sensor_msgs::ImagePtr prepareDbgImage(const sensor_msgs::ImageConstPtr &depth_msg, const std::list< std::pair< unsigned, unsigned >> &ground_points_indices)
void setRansacMaxIter(const unsigned u)
void setRangeLimits(const float rmin, const float rmax)
void setReconfParamsUpdated(bool updated)
setReconfParamsUpdated
void calcDeltaAngleForImgRows(double vertical_fov)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
float range_min_
Stores the current minimum range to use.
unsigned depth_image_step_col_
Columns step in depth processing (px).
void fieldOfView(double &min, double &max, double x1, double y1, double xc, double yc, double x2, double y2)
float mount_height_max_
Max height of sensor mount from ground.
sensor_msgs::ImageConstPtr getDbgImage() const
double angleBetweenRays(const cv::Point3d &ray1, const cv::Point3d &ray2) const
void estimateParams(const sensor_msgs::ImageConstPtr &depth_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
double lengthOfVector(const cv::Point3d &vec) const
double min(double a, double b)
void setSensorMountHeightMin(const float height)
setSensorMountHeight sets the height of sensor mount (in meters) from ground
void setDepthImgStepCol(const int step)
setDepthImgStepCol
void setDepthImgStepRow(const int step)
setDepthImgStepRow
unsigned int step
void setCamModelUpdate(const bool u)
setCamModelUpdate
void sensorPoseCalibration(const sensor_msgs::ImageConstPtr &depth_msg, double &tilt_angle, double &height)
unsigned used_depth_height_
Used depth height from img bottom (px)
void setGroundMaxPoints(const unsigned u)
void setRansacDistanceThresh(const float u)
void setSensorTiltAngleMax(const float angle)
setSensorTiltAngle sets the sensor tilt angle (in degrees)
unsigned depth_image_step_row_
Rows step in depth processing (px).
void setSensorMountHeightMax(const float height)
setSensorMountHeight sets the height of sensor mount (in meters) from ground
float range_max_
Stores the current maximum range to use.
double max(double a, double b)
bool publish_depth_enable_
Determines if debug image should be published.
bool getPublishDepthEnable() const
getPublishDepthEnable
void setSensorTiltAngleMin(const float angle)
setSensorTiltAngle sets the sensor tilt angle (in degrees)
void setPublishDepthEnable(const bool enable)
setPublishDepthEnable
DepthSensorPose & operator=(const DepthSensorPose &)=delete


depth_sensor_pose
Author(s): Michal Drwiega (http://www.mdrwiega.com)
autogenerated on Wed May 5 2021 02:56:10