RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
human_detection.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright 2015 RAPP
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 
16 ******************************************************************************/
17 
19 
20 
25 {
26  // Fetching the service topic URI parameter
27  if(!nh_.getParam("/rapp_human_detection_detect_humans_topic", humanDetectionTopic_))
28  {
29  ROS_ERROR("Human detection topic param does not exist");
30  }
31  // Creating the service server concerning the human detection functionality
34 }
35 
43  rapp_platform_ros_communications::HumanDetectionRosSrv::Request& req,
44  rapp_platform_ros_communications::HumanDetectionRosSrv::Response& res)
45 {
46  std::vector<unsigned int [4]> history;
47  std::vector<cv::Rect> humans = human_detector_.findHuman2D(req.imageFilename); // run detectHuman2D
48  for(unsigned int i = 0 ; i < humans.size() ; i++)
49  {
50 
51  unsigned int temp[4];
52  temp[0] = humans[i].x;
53  temp[1] = humans[i].y;
54  temp[2] = humans[i].x + humans[i].width;
55  temp[3] = humans[i].y + humans[i].height;
56 
57  bool duplicate = false;
58  for(unsigned int j = 0 ; j < history.size() ; j++)
59  {
60  if(temp[0] == history[j][0] && temp[1] == history[j][1] &&
61  temp[2] == history[j][2] && temp[3] == history[j][3])
62  {
63  duplicate = true;
64  break;
65  }
66  }
67  if(duplicate)
68  {
69  continue;
70  }
71 
72  geometry_msgs::PointStamped up_left_corner;
73  geometry_msgs::PointStamped down_right_corner;
74 
75  up_left_corner.point.x = temp[0];
76  up_left_corner.point.y = temp[1];
77  down_right_corner.point.x = temp[2];
78  down_right_corner.point.y = temp[3];
79 
80  //responses
81  res.humans_up_left.push_back(up_left_corner);
82  res.humans_down_right.push_back(down_right_corner);
83  }
84 
85  return true;
86 }
std::vector< cv::Rect > findHuman2D(std::string file_name)
Finds humans in an image retrieved from a file URL.
HumanDetector human_detector_
HumanDetection(void)
Default constructor.
bool humanDetectionCallback(rapp_platform_ros_communications::HumanDetectionRosSrv::Request &req, rapp_platform_ros_communications::HumanDetectionRosSrv::Response &res)
Serves the human detection ROS service callback.
std::string humanDetectionTopic_
ros::NodeHandle nh_
ros::ServiceServer humanDetectionService_