Go to the documentation of this file.00001 #ifndef _HECTOR_MOTION_DETECTION_H_
00002 #define _HECTOR_MOTION_DETECTION_H_
00003
00004 #include <ros/ros.h>
00005
00006 #include <queue>
00007
00008 #include <opencv/cv.h>
00009 #include <cv_bridge/cv_bridge.h>
00010 #include <opencv2/opencv.hpp>
00011 #include <opencv2/highgui/highgui.hpp>
00012
00013 #include <image_transport/image_transport.h>
00014
00015 #include <std_msgs/String.h>
00016 #include <sensor_msgs/image_encodings.h>
00017 #include <sensor_msgs/CompressedImage.h>
00018
00019 #include <hector_worldmodel_msgs/ImagePercept.h>
00020
00021 #include <dynamic_reconfigure/server.h>
00022 #include <hector_motion_detection/MotionDetectionConfig.h>
00023
00024
00025
00026 using hector_motion_detection::MotionDetectionConfig;
00027
00028 class MotionDetection
00029 {
00030 public:
00031 MotionDetection();
00032 ~MotionDetection();
00033
00034 typedef std::vector<cv::KeyPoint> KeyPoints;
00035
00036 private:
00037 void colorizeDepth(const cv::Mat& gray, cv::Mat& rgb) const;
00038 void drawOpticalFlowVectors(cv::Mat& img, const cv::Mat& optical_flow, int step = 10, const cv::Scalar& color = CV_RGB(0, 255, 0)) const;
00039
00040 void computeOpticalFlow(const cv::Mat& prev_img, const cv::Mat& cur_img, cv::Mat& optical_flow, bool use_initial_flow = false, bool filter = false) const;
00041 void computeOpticalFlowMagnitude(const cv::Mat& optical_flow, cv::Mat& optical_flow_mag) const;
00042
00043 void drawBlobs(cv::Mat& img, const KeyPoints& keypoints, double scale = 1.0) const;
00044 void detectBlobs(const cv::Mat& img, KeyPoints& keypoints) const;
00045
00046 void update(const ros::TimerEvent& event);
00047
00048 void imageCallback(const sensor_msgs::ImageConstPtr& img);
00049
00050 void dynRecParamCallback(MotionDetectionConfig& config, uint32_t level);
00051
00052 ros::Timer update_timer;
00053
00054 image_transport::Subscriber image_sub_;
00055
00056 ros::Publisher image_percept_pub_;
00057 image_transport::CameraSubscriber camera_sub_;
00058 image_transport::CameraPublisher image_motion_pub_;
00059 image_transport::CameraPublisher image_detected_pub_;
00060
00061 dynamic_reconfigure::Server<MotionDetectionConfig> dyn_rec_server_;
00062
00063 sensor_msgs::ImageConstPtr last_img;
00064
00065 cv_bridge::CvImageConstPtr img_prev_ptr_;
00066 cv_bridge::CvImageConstPtr img_prev_col_ptr_;
00067
00068 cv::Mat optical_flow;
00069 std::list<cv::Mat> flow_history;
00070
00071
00072 double motion_detect_downscale_factor_;
00073 double motion_detect_inv_sensivity_;
00074 bool motion_detect_use_initial_flow_;
00075 bool motion_detect_image_flow_filter_;
00076 int motion_detect_threshold_;
00077 double motion_detect_min_area_;
00078 double motion_detect_min_blob_dist_;
00079 int motion_detect_dilation_size_;
00080 int motion_detect_flow_history_size_;
00081 std::string percept_class_id_;
00082 };
00083
00084 #endif