Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00052
00053 #include <iostream>
00054 #include <float.h>
00055
00056 #include <PeopleDetector.h>
00057
00058
00059 #include <ros/ros.h>
00060 #include <ros/node_handle.h>
00061 #include <sensor_msgs/LaserScan.h>
00062
00063 using namespace std;
00064
00065
00066 class PeopleDetectorNode
00067 {
00068 public:
00069 ros::NodeHandle nh_;
00070
00071 sensor_msgs::LaserScan scan_ouput_;
00072
00073 ros::Subscriber scan_;
00074 ros::Publisher scan_publish_;
00075
00076 string input_scan_topic_, output_scan_topic_;
00077 string hypotheses_filename_;
00078 int num_hypotheses_;
00079 double threshold_;
00080 FILE *f_hypotheses;
00081 int list_size_;
00082
00083 PeopleDetector pd;
00084
00088 PeopleDetectorNode() : nh_("~")
00089 {
00090 nh_.param("input_scan_topic", input_scan_topic_, std::string("/scan"));
00091 nh_.param("output_scan_topic", output_scan_topic_, std::string("people_detected"));
00092 nh_.param("threshold", threshold_, 0.15);
00093 nh_.param("hypotheses_filename", hypotheses_filename_, std::string(""));
00094 nh_.param("num_hypotheses", num_hypotheses_, 100);
00095 nh_.param("list_size", list_size_, 500);
00096 if (hypotheses_filename_ == "")
00097 {
00098 ROS_ERROR("Provide hypotheses file!!");
00099 exit(2);
00100 }
00101 scan_ = nh_.subscribe<sensor_msgs::LaserScan>(input_scan_topic_, 10, &PeopleDetectorNode::scan_cb, this);
00102 scan_publish_ = nh_.advertise<sensor_msgs::LaserScan> (output_scan_topic_, 1);
00103 }
00104
00108 ~PeopleDetectorNode()
00109 {
00110 fclose( f_hypotheses );
00111 }
00112
00116 void init ()
00117 {
00118 try
00119 {
00120 f_hypotheses = fopen(hypotheses_filename_.c_str(), "r");
00121 if ( f_hypotheses == NULL )
00122 {
00123 ROS_ERROR("ERROR opening hypotesis file %s", hypotheses_filename_.c_str());
00124 throw -1;
00125 }
00126 }
00127 catch (int e)
00128 {
00129 }
00130
00131 pd.load(f_hypotheses, num_hypotheses_);
00132 }
00133
00138 void scan_cb(const sensor_msgs::LaserScan::ConstPtr &msg)
00139 {
00140 scan_ouput_.intensities.clear();
00141 scan_ouput_ = *msg;
00142
00143
00144 dyntab_segments *list_segments=NULL;
00145 int num_readings = msg->ranges.size();
00146 double *angles = new double[num_readings];
00147 double *ranges = new double[num_readings];
00148
00149 for (unsigned int i = 0; i < num_readings; i++)
00150 {
00151 ranges[i] = msg->ranges[i];
00152 angles[i] = msg->angle_min + i * msg->angle_increment;
00153 }
00154 list_segments = new dyntab_segments (list_size_);
00155
00156 pd.segmentScan(threshold_, num_readings, angles, ranges, list_segments);
00157
00158
00159 for (int i=0; i < list_segments->num(); i++)
00160 {
00161 Segment *s = list_segments->getElement(i);
00162
00163 if ( s->num() < 3 )
00164 {
00165 s->type = -1;
00166 }
00167 else
00168 {
00169 pd.classify(s);
00170 if ( s->type == 1)
00171 {
00172 printf("People found\n");
00173 }
00174 else
00175 {
00176 printf("__NO__ People found\n");
00177
00178 }
00179
00180 }
00181 }
00182
00183 for (int i=0; i < list_segments->num(); i++)
00184 {
00185 Segment *s = list_segments->getElement(i);
00186 for (int out = 0; out < s->num(); out++)
00187 {
00188 if (s->type == 1)
00189 scan_ouput_.intensities.push_back(1);
00190 else
00191 scan_ouput_.intensities.push_back(0);
00192 }
00193 }
00194 scan_publish_.publish(scan_ouput_);
00195
00196 list_segments->setAutoDelete(true);
00197 delete list_segments;
00198 list_segments = NULL;
00199
00200
00201 delete [] ranges;
00202 delete [] angles;
00203 }
00204
00205 };
00206
00207
00208
00209 int main (int argc, char** argv)
00210 {
00211 ros::init (argc, argv, "people_detector_node");
00212 PeopleDetectorNode pd_node;
00213 pd_node.init();
00214 ros::spin ();
00215 return (0);
00216 }
00217
00218