map_keyframe_based.h
Go to the documentation of this file.
00001 
00008 #ifndef UCL_DRONE_SIMPLE_MAP_H
00009 #define UCL_DRONE_SIMPLE_MAP_H
00010 #define PCL_NO_PRECOMPILE
00011 
00012 #define USE_PROFILING
00013 #include <ucl_drone/profiling.h>
00014 
00015 // #define DEBUG_PROJECTION  // if defined print relative errors of projection for the target
00016 
00017 /* Header files */
00018 #include <ucl_drone/ucl_drone.h>
00019 
00020 #include <ros/package.h>
00021 #include <ros/ros.h>
00022 #include <tf/transform_datatypes.h>
00023 
00024 // vision
00025 #include <opencv2/calib3d/calib3d.hpp>
00026 #include <opencv2/core/core.hpp>
00027 #include <opencv2/imgproc/imgproc.hpp>
00028 #include <opencv2/nonfree/features2d.hpp>
00029 #include <opencv2/nonfree/nonfree.hpp>
00030 
00031 /* Point Cloud library */
00032 #include <pcl/visualization/point_cloud_geometry_handlers.h>
00033 
00034 #include <pcl/common/common_headers.h>
00035 #include <pcl/point_types.h>  // pcl::PointXYZRGB
00036 #include <pcl/visualization/cloud_viewer.h>
00037 #include <pcl/visualization/pcl_visualizer.h>
00038 #include <pcl_conversions/pcl_conversions.h>  // pcl::fromROSMsg
00039 #include <pcl_ros/point_cloud.h>              // pcl::PointCloud
00040 
00041 /* Boost */
00042 #include <boost/shared_ptr.hpp>
00043 #include <boost/thread/thread.hpp>
00044 
00045 /* Messages */
00046 //#include <sensor_msgs/PointCloud2.h>  // sensor_msgs::PointCloud2
00047 #include <sensor_msgs/image_encodings.h>
00048 #include <std_msgs/Empty.h>
00049 
00050 /* ucl_drone */
00051 #include <ucl_drone/PointXYZRGBSIFT.h>  // pcl::PointXYZRGBSIFT
00052 #include <ucl_drone/Pose3D.h>
00053 #include <ucl_drone/ProcessedImageMsg.h>
00054 #include <ucl_drone/TargetDetected.h>
00055 #include <ucl_drone/map/projection_2D.h>
00056 #include <ucl_drone/opencv_utils.h>
00057 #include <ucl_drone/read_from_launch.h>
00058 
00059 #include <ucl_drone/map/frame.h>
00060 #include <ucl_drone/map/keyframe.h>
00061 
00062 // to print the pointcloud at the console
00063 void cloud_debug(pcl::PointCloud< pcl::PointXYZRGBSIFT >::ConstPtr cloud);
00064 
00068 class Map
00069 {
00070 private:
00071   /* Attributes */
00072 
00073   ros::NodeHandle nh;
00074 
00075   bool processedImgReceived;   
00076   ucl_drone::Pose3D PnP_pose;  
00077   bool tracking_lost;  
00078 
00079   bool do_search;      
00080   bool stop_if_lost;   
00081 
00082   /* Subscribers */
00083   ros::Subscriber processed_image_sub;  
00084   std::string processed_image_channel_in;
00085   ros::Subscriber reset_pose_sub;  
00086   std::string reset_pose_channel;
00087   ros::Subscriber end_reset_pose_sub;  
00088   std::string end_reset_pose_channel;
00089 
00090   /* Publishers */
00091   ros::Publisher pose_PnP_pub;  
00092   std::string pose_PnP_channel;
00093   ros::Publisher pose_correction_pub;  
00094 
00095   std::string pose_correction_channel;
00096   ros::Publisher target_pub;  
00097   std::string target_channel_out;
00098 
00099   /* Tresholds for PnP */
00100   int threshold_lost;          
00101 
00102   int threshold_new_keyframe;  
00103 
00104   double threshold_new_keyframe_percentage;  
00105 
00106 
00108   void processedImageCb(const ucl_drone::ProcessedImageMsg::ConstPtr processed_image_in);
00109 
00115   bool doPnP(Frame current_frame, ucl_drone::Pose3D& PnP_pose, std::vector< int >& inliers,
00116              KeyFrame* ref_keyframe);
00117 
00122   bool closestKeyFrame(const ucl_drone::Pose3D& pose, int& keyframe_ID, Frame current_frame);
00123 
00124   // Measure
00125   ucl_drone::ProcessedImageMsg::ConstPtr lastProcessedImgReceived;  
00126 
00127   /* Services Definition */
00128 
00129   cv::Mat camera_matrix_K;
00130 
00131   cv::Mat tvec;  
00132   cv::Mat rvec;  
00133 
00134   Frame previous_frame;          
00135   KeyFrame* reference_keyframe;  
00136 
00137   cv::Mat cam_plane_top;
00138   cv::Mat cam_plane_bottom;
00139   cv::Mat cam_plane_left;
00140   cv::Mat cam_plane_right;
00141 
00144   void init_planes();
00145 
00147   void resetPoseCb(const std_msgs::Empty& msg);
00148 
00150   void endResetPoseCb(const std_msgs::Empty& msg);
00151 
00156   bool newKeyFrameNeeded(int number_of_common_keypoints);
00157   bool newKeyFrameNeeded(int number_of_common_keypoints, KeyFrame* reference_keyframe_candidate);
00158 
00159 public:
00160   bool pending_reset;  
00161 
00163   pcl::PointCloud< pcl::PointXYZRGBSIFT >::Ptr cloud;
00164 
00166   boost::shared_ptr< pcl::visualization::PCLVisualizer > visualizer;
00167 
00169   Map();
00170 
00172   ~Map();
00173 
00175   void getDescriptors(const ucl_drone::Pose3D& pose, cv::Mat& descriptors, std::vector< int >& idx,
00176                       bool only_visible = true);
00177 
00179   void getDescriptors(const std::vector< int >& idx, cv::Mat& descriptors);
00180 
00185   void getVisibleKeyFrames(const ucl_drone::Pose3D& pose,
00186                            std::vector< std::vector< int > >& keyframes_ID);
00187 
00191   void getVisiblePoints(const ucl_drone::Pose3D& pose, std::vector< int >& idx);
00192 
00195   void targetDetectedPublisher();
00196 
00200   void publishPoseVisual(ucl_drone::Pose3D poseFrame, ucl_drone::Pose3D posePnP);
00201 };
00202 
00203 #endif /* UCL_DRONE_SIMPLE_MAP_H */


ucl_drone
Author(s): dronesinma
autogenerated on Sat Jun 8 2019 20:51:53