depth_sensor_pose.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2016, Michal Drwiega (drwiega.michal@gmail.com)
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *     1. Redistributions of source code must retain the above copyright
00010  *        notice, this list of conditions and the following disclaimer.
00011  *     2. Redistributions in binary form must reproduce the above copyright
00012  *        notice, this list of conditions and the following disclaimer in the
00013  *        documentation and/or other materials provided with the distribution.
00014  *     3. Neither the name of the copyright holder nor the names of its
00015  *        contributors may be used to endorse or promote products derived
00016  *        from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00024  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00026  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *****************************************************************************/
00037 #ifndef DEPTH_SENSOR_POSE
00038 #define DEPTH_SENSOR_POSE
00039 
00040 #include <ros/console.h>
00041 #include <ros/ros.h>
00042 
00043 #include <sensor_msgs/Image.h>
00044 #include <sensor_msgs/LaserScan.h>
00045 #include <sensor_msgs/image_encodings.h>
00046 #include <image_geometry/pinhole_camera_model.h>
00047 
00048 #include <sstream>
00049 #include <limits.h>
00050 #include <math.h>
00051 #include <vector>
00052 #include <cmath>
00053 #include <string>
00054 #include <boost/lexical_cast.hpp>
00055 #include <iostream>
00056 #include <fstream>
00057 
00058 #include <pcl/point_types.h>
00059 #include <pcl/sample_consensus/ransac.h>
00060 #include <pcl/sample_consensus/sac_model_plane.h>
00061 #include <pcl/sample_consensus/method_types.h>
00062 #include <pcl/sample_consensus/model_types.h>
00063 #include <pcl/segmentation/sac_segmentation.h>
00064 
00065 #include <Eigen/Core>
00066 
00067 #define DEBUG 1
00068 
00069 //#define               DATA_TO_FILE
00070 //#define       DEBUG_INFO
00071 //#define               DEBUG_CALIBRATION
00072 
00073 namespace depth_sensor_pose
00074 { 
00075 class DepthSensorPose
00076 {
00077   //----------------------------------------------------------------------------
00078 public:
00079   DepthSensorPose();
00080   ~DepthSensorPose();
00081 
00094   void estimateParams(const sensor_msgs::ImageConstPtr& depth_msg,
00095                    const sensor_msgs::CameraInfoConstPtr& info_msg);
00106   void setRangeLimits(const float rmin, const float rmax);
00107 
00113   void setSensorMountHeightMin (const float height);
00119   void setSensorMountHeightMax (const float height);
00124   void setSensorTiltAngleMin (const float angle);
00129   void setSensorTiltAngleMax (const float angle);
00134   void setPublishDepthEnable (const bool enable) { publish_depth_enable_ = enable; }
00139   bool getPublishDepthEnable () const { return publish_depth_enable_; }
00144   void setCamModelUpdate (const bool u) { cam_model_update_ = u; }
00149   void setUsedDepthHeight(const unsigned int height);
00154   void setDepthImgStepRow(const int step);
00159   void setDepthImgStepCol(const int step);
00164   void setReconfParamsUpdated (bool updated) {reconf_serv_params_updated_ = updated; }
00165 
00166 
00167 
00168 
00169   void setRansacMaxIter (const unsigned int u)   { ransacMaxIter_ = u; }
00170 
00171   void setRansacDistanceThresh (const float u)   { ransacDistanceThresh_ = u; }
00172 
00173   void setGroundMaxPoints (const unsigned int u)   { max_ground_points_ = u; }
00174   //------------------------------------------------------------------------
00175 
00179   float getSensorTiltAngle () const { return tilt_angle_est_; }
00183   float getSensorMountHeight () const { return mount_height_est_; }
00184 
00185   //---------------------------------------------------------------------------------------------
00186 private: // Private methods
00196   double lengthOfVector( const cv::Point3d& ray) const;
00197 
00209   double angleBetweenRays( const cv::Point3d& ray1, const cv::Point3d& ray2) const;
00218   void fieldOfView( double & min, double & max, double x1, double y1,
00219                     double xc, double yc, double x2, double y2 );
00224   void calcDeltaAngleForImgRows( double vertical_fov);
00234   void calcGroundDistancesForImgRows( double mount_height, double tilt_angle,
00235                                       std::vector<unsigned int>& distances);
00239   void getGroundPoints(const sensor_msgs::ImageConstPtr& depth_msg,
00240                        pcl::PointCloud<pcl::PointXYZ>::Ptr& points);
00244   void sensorPoseCalibration(const sensor_msgs::ImageConstPtr& depth_msg, double & tilt, double & height);
00245 
00246   //-----------------------------------------------------------------------------------------------
00247 public: // Public fields
00248 
00249   sensor_msgs::Image new_depth_msg_;
00250 
00251 private: // Private fields
00252 
00253   //----------------------------------------------------------------------------
00254   // ROS parameters configurated with config files or dynamic_reconfigure
00255   float        range_min_;            
00256   float        range_max_;            
00257 
00258   float        mount_height_min_;     
00259   float        mount_height_max_;     
00260   float        tilt_angle_min_;       
00261   float        tilt_angle_max_;       
00262 
00263   bool         publish_depth_enable_; 
00264   bool         cam_model_update_;     
00265   unsigned int used_depth_height_;    
00266   unsigned int depth_image_step_row_; 
00267   unsigned int depth_image_step_col_; 
00268 
00269   unsigned int max_ground_points_;
00270 
00271   unsigned int ransacMaxIter_;
00272   float ransacDistanceThresh_;
00273   float groundDistTolerance_;
00274 
00275 
00276   //----------------------------------------------------------------------------
00277 
00279   image_geometry::PinholeCameraModel camera_model_;
00280 
00281   std::vector<double> delta_row_;
00282 
00283   float mount_height_est_;
00284   float tilt_angle_est_;
00285 
00286   bool  reconf_serv_params_updated_;
00287 
00288   std::vector<unsigned int>dist_to_ground_max_;
00289   std::vector<unsigned int>dist_to_ground_min_;
00290 
00291 };
00292 
00293 template <typename T>
00294 std::string NumberToString ( T Number )
00295 {
00296   std::ostringstream ss;
00297   ss << Number;
00298   return ss.str();
00299 }
00300 
00301 } // depth_sensor_pose
00302 
00303 #endif


depth_sensor_pose
Author(s): Michal Drwiega
autogenerated on Thu Jun 6 2019 22:10:50