00001 00060 #ifndef _FACE_CAPTURE_NODE_ 00061 #define _FACE_CAPTURE_NODE_ 00062 00063 // standard includes 00064 #include <sstream> 00065 #include <string> 00066 #include <vector> 00067 00068 // ROS includes 00069 #include <ros/ros.h> 00070 #include <ros/package.h> 00071 00072 // ROS message includes 00073 #include <sensor_msgs/Image.h> 00074 //#include <cob_perception_msgs/DetectionArray.h> 00075 #include <cob_perception_msgs/ColorDepthImageArray.h> 00076 00077 // topics 00078 #include <message_filters/subscriber.h> 00079 #include <message_filters/synchronizer.h> 00080 #include <message_filters/sync_policies/approximate_time.h> 00081 #include <image_transport/image_transport.h> 00082 #include <image_transport/subscriber_filter.h> 00083 00084 // actions 00085 #include <actionlib/server/simple_action_server.h> 00086 #include <cob_people_detection/addDataAction.h> 00087 #include <cob_people_detection/updateDataAction.h> 00088 #include <cob_people_detection/deleteDataAction.h> 00089 00090 // services 00091 #include <cob_people_detection/captureImage.h> 00092 #include <cob_people_detection/finishRecording.h> 00093 00094 // opencv 00095 #include <opencv/cv.h> 00096 #include <opencv/highgui.h> 00097 #include <cv_bridge/cv_bridge.h> 00098 #include <sensor_msgs/image_encodings.h> 00099 00100 // boost 00101 #include <boost/bind.hpp> 00102 #include <boost/thread/mutex.hpp> 00103 00104 // external includes 00105 #include "cob_vision_utils/GlobalDefines.h" 00106 00107 #include "cob_people_detection/face_recognizer.h" 00108 00109 namespace ipa_PeopleDetector 00110 { 00111 00112 typedef actionlib::SimpleActionServer<cob_people_detection::addDataAction> AddDataServer; 00113 typedef actionlib::SimpleActionServer<cob_people_detection::updateDataAction> UpdateDataServer; 00114 typedef actionlib::SimpleActionServer<cob_people_detection::deleteDataAction> DeleteDataServer; 00115 00116 class FaceCaptureNode 00117 { 00118 protected: 00119 00120 ros::NodeHandle node_handle_; 00121 00122 // mutex 00123 boost::mutex active_action_mutex_; 00124 00125 // face recognizer trainer 00126 FaceRecognizer face_recognizer_trainer_; 00127 std::vector<cv::Mat> face_images_; 00128 std::vector<cv::Mat> face_depthmaps_; 00129 std::string current_label_; 00130 bool capture_image_; 00131 int number_captured_images_; 00132 bool finish_image_capture_; 00133 enum CaptureMode 00134 { 00135 MANUAL = 0, CONTINUOUS 00136 }; 00137 enum UpdateMode 00138 { 00139 BY_INDEX = 1, BY_LABEL 00140 }; 00141 //enum DeleteMode {BY_INDEX=1, BY_LABEL}; 00142 00143 image_transport::ImageTransport* it_; 00144 // image_transport::SubscriberFilter people_segmentation_image_sub_; ///< Color camera image topic 00145 // message_filters::Synchronizer<message_filters::sync_policies::ApproximateTime<cob_perception_msgs::DetectionArray, cob_perception_msgs::ColorDepthImageArray, sensor_msgs::Image> >* sync_input_3_; 00146 // message_filters::Subscriber<cob_perception_msgs::DetectionArray> face_recognition_subscriber_; ///< receives the face messages from the detection tracker 00147 message_filters::Synchronizer<message_filters::sync_policies::ApproximateTime<cob_perception_msgs::ColorDepthImageArray, sensor_msgs::Image> >* sync_input_2_; 00148 message_filters::Subscriber<cob_perception_msgs::ColorDepthImageArray> face_detection_subscriber_; 00149 image_transport::SubscriberFilter color_image_sub_; 00150 00151 // actions 00152 AddDataServer* add_data_server_; 00153 UpdateDataServer* update_data_server_; 00154 DeleteDataServer* delete_data_server_; 00155 00156 // services 00157 ros::ServiceServer service_server_capture_image_; 00158 ros::ServiceServer service_server_finish_recording_; 00159 00160 // parameters 00161 std::string data_directory_; 00162 // bool display_; ///< if on, several debug outputs are activated 00163 // bool use_people_segmentation_; ///< enables the combination of face detections with the openni people segmentation 00164 // double face_redetection_time_; ///< timespan during which a face is preserved in the list of tracked faces although it is currently not visible 00165 // double min_segmented_people_ratio_color_; ///< the minimum area inside the face rectangle found in the color image that has to be covered with positive people segmentation results (from openni_tracker) 00166 // double min_segmented_people_ratio_range_; ///< the minimum area inside the face rectangle found in the range image that has to be covered with positive people segmentation results (from openni_tracker) 00167 // double tracking_range_m_; ///< maximum tracking manhattan distance for a face (in meters), i.e. a face can move this distance between two images and can still be tracked 00168 // double face_identification_score_decay_rate_; ///< face identification score decay rate (0 < x < 1), i.e. the score for each label at a certain detection location is multiplied by this factor 00169 // double min_face_identification_score_to_publish_; ///< minimum face identification score to publish (0 <= x < max_score), i.e. this score must be exceeded by a label at a detection location before the person detection is published (higher values increase robustness against short misdetections, but consider the maximum possible score max_score w.r.t. the face_identification_score_decay_rate: new_score = (old_score+1)*face_identification_score_decay_rate --> max_score = face_identification_score_decay_rate/(1-face_identification_score_decay_rate)) 00170 // bool fall_back_to_unknown_identification_; ///< if this is true, the unknown label will be assigned for the identification of a person if it has the highest score, otherwise, the last detection of a name will display as label even if there has been a detection of Unknown recently for that face 00171 00172 00173 void addDataServerCallback(const cob_people_detection::addDataGoalConstPtr& goal); 00174 00176 void inputCallback(const cob_perception_msgs::ColorDepthImageArray::ConstPtr& face_detection_msg);//, const sensor_msgs::Image::ConstPtr& color_image_msg); 00177 00179 unsigned long convertColorImageMessageToMat(const sensor_msgs::Image::ConstPtr& image_msg, cv_bridge::CvImageConstPtr& image_ptr, cv::Mat& image); 00180 unsigned long convertDepthImageMessageToMat(const sensor_msgs::Image::ConstPtr& image_msg, cv_bridge::CvImageConstPtr& image_ptr, cv::Mat& image); 00181 00182 bool captureImageCallback(cob_people_detection::captureImage::Request &req, cob_people_detection::captureImage::Response &res); 00183 00184 bool finishRecordingCallback(cob_people_detection::finishRecording::Request &req, cob_people_detection::finishRecording::Response &res); 00185 00186 void updateDataServerCallback(const cob_people_detection::updateDataGoalConstPtr& goal); 00187 00188 void deleteDataServerCallback(const cob_people_detection::deleteDataGoalConstPtr& goal); 00189 00190 public: 00191 00192 FaceCaptureNode(ros::NodeHandle nh); 00193 ~FaceCaptureNode(); 00194 }; 00195 00196 } 00197 ; 00198 00199 #endif // _FACE_CAPTURE_NODE_