Go to the documentation of this file.00001 #include "human_assisted_object_detection_alg_node.h"
00002
00003 HumanAssistedObjectDetectionAlgNode::HumanAssistedObjectDetectionAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<HumanAssistedObjectDetectionAlgorithm>(),
00005 it_(this->public_node_handle_)
00006 {
00007
00008
00009
00010
00011 this->output_image_publisher_ = it_.advertise("output_image", 1);
00012
00013
00014 this->face_detect_subscriber_ = this->public_node_handle_.subscribe("face_detect", 100, &HumanAssistedObjectDetectionAlgNode::face_detect_callback, this);
00015 this->input_image_subscriber_ = it_.subscribe("input_image", 1, &HumanAssistedObjectDetectionAlgNode::input_image_callback, this);
00016
00017
00018 this->learn_server_ = this->public_node_handle_.advertiseService("learn", &HumanAssistedObjectDetectionAlgNode::learnCallback, this);
00019 this->detect_server_ = this->public_node_handle_.advertiseService("detect", &HumanAssistedObjectDetectionAlgNode::detectCallback, this);
00020 this->init_server_ = this->public_node_handle_.advertiseService("init", &HumanAssistedObjectDetectionAlgNode::initCallback, this);
00021
00022
00023
00024
00025
00026
00027 this->receiving_detections=false;
00028 this->receiving_images=false;
00029 }
00030
00031 HumanAssistedObjectDetectionAlgNode::~HumanAssistedObjectDetectionAlgNode(void)
00032 {
00033
00034 }
00035
00036 void HumanAssistedObjectDetectionAlgNode::mainNodeThread(void)
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046 }
00047
00048
00049 void HumanAssistedObjectDetectionAlgNode::face_detect_callback(const face_detector_mono::RectArray::ConstPtr& msg)
00050 {
00051
00052
00053
00054 this->face_detect_mutex_.enter();
00055
00056 if(msg->rects.size()!=0)
00057 {
00058 this->face_rects.rects.resize(msg->rects.size());
00059 for(unsigned int i=0; i<msg->rects.size(); i++)
00060 {
00061 this->face_rects.rects[i].x=msg->rects[i].x;
00062 this->face_rects.rects[i].width=msg->rects[i].width;
00063 this->face_rects.rects[i].y=msg->rects[i].y;
00064 this->face_rects.rects[i].height=msg->rects[i].height;
00065 }
00066 this->receiving_detections=true;
00067 }
00068 else
00069 {
00070 this->receiving_detections=false;
00071 }
00072
00073
00074
00075
00076 this->face_detect_mutex_.exit();
00077 }
00078 void HumanAssistedObjectDetectionAlgNode::input_image_callback(const sensor_msgs::Image::ConstPtr& msg)
00079 {
00080 static bool first=true;
00081
00082
00083
00084
00085 this->alg_.lock();
00086 this->input_image_mutex_.enter();
00087
00088
00089 this->input_image=msg;
00090 if(first)
00091 {
00092 this->receiving_images=true;
00093 first=false;
00094 }
00095
00096
00097 this->input_image_mutex_.exit();
00098 this->alg_.unlock();
00099 }
00100
00101
00102 bool HumanAssistedObjectDetectionAlgNode::learnCallback(iri_human_assisted_object_detection::haod_learn::Request &req, iri_human_assisted_object_detection::haod_learn::Response &res)
00103 {
00104 ROS_INFO("HumanAssistedObjectDetectionAlgNode::learnCallback: New Request Received!");
00105
00106
00107
00108
00109
00110 this->alg_.learn_detector(req.valid);
00111 this->alg_.get_output_image(this->Image_msg_);
00112 this->output_image_publisher_.publish(this->Image_msg_);
00113
00114
00115
00116
00117
00118 return true;
00119 }
00120 bool HumanAssistedObjectDetectionAlgNode::detectCallback(iri_human_assisted_object_detection::haod_detect::Request &req, iri_human_assisted_object_detection::haod_detect::Response &res)
00121 {
00122 ROS_INFO("HumanAssistedObjectDetectionAlgNode::detectCallback: New Request Received!");
00123
00124
00125
00126
00127
00128 if(this->alg_.detect(this->input_image))
00129 {
00130 res.success=true;
00131 ROS_INFO("HumanAssistedObjectDetectionAlgNode::detectCallback: assistance needed!");
00132 }
00133 else
00134 {
00135 res.success=false;
00136 }
00137 this->alg_.get_output_image(this->Image_msg_);
00138 this->alg_.get_output_rect(this->rect);
00139 res.x=rect.x;
00140 res.y=rect.y;
00141 this->output_image_publisher_.publish(this->Image_msg_);
00142
00143
00144
00145
00146
00147 return true;
00148 }
00149 bool HumanAssistedObjectDetectionAlgNode::initCallback(iri_human_assisted_object_detection::haod_init::Request &req, iri_human_assisted_object_detection::haod_init::Response &res)
00150 {
00151
00152 ROS_INFO("HumanAssistedObjectDetectionAlgNode::initCallback: New Request Received!");
00153
00154
00155
00156
00157 this->face_detect_mutex_.enter();
00158 if(this->receiving_detections && this->receiving_images)
00159 {
00160 for(unsigned int i=0;i<this->face_rects.rects.size();i++)
00161 {
00162 if(req.x > (this->face_rects.rects[i].x-this->face_rects.rects[i].width/2.0) &&
00163 req.x < (this->face_rects.rects[i].x+this->face_rects.rects[i].width/2.0) &&
00164 req.y > (this->face_rects.rects[i].y-this->face_rects.rects[i].height/2.0) &&
00165 req.y < (this->face_rects.rects[i].y+this->face_rects.rects[i].height/2.0))
00166 {
00167 if(this->alg_.init_detector(this->input_image,this->face_rects.rects[i]))
00168 res.success=true;
00169 else
00170 res.success=false;
00171 }
00172 this->face_detect_mutex_.exit();
00173 return true;
00174 }
00175 res.success=false;
00176 }
00177 else
00178 res.success=false;
00179
00180
00181
00182
00183 this->face_detect_mutex_.exit();
00184 return true;
00185 }
00186
00187
00188
00189
00190
00191 void HumanAssistedObjectDetectionAlgNode::node_config_update(Config &config, uint32_t level)
00192 {
00193 this->alg_.lock();
00194
00195 this->alg_.unlock();
00196 }
00197
00198 void HumanAssistedObjectDetectionAlgNode::addNodeDiagnostics(void)
00199 {
00200 }
00201
00202
00203 int main(int argc,char *argv[])
00204 {
00205 return algorithm_base::main<HumanAssistedObjectDetectionAlgNode>(argc, argv, "human_assisted_object_detection_alg_node");
00206 }