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
face_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_face_detection_detect_faces_topic", faceDetectionTopic_))
28  {
29  ROS_ERROR("Face detection topic param does not exist");
30  }
31  // Creating the service server concerning the face detection functionality
34 }
35 
43  rapp_platform_ros_communications::FaceDetectionRosSrv::Request& req,
44  rapp_platform_ros_communications::FaceDetectionRosSrv::Response& res)
45 {
46  std::vector<unsigned int [4]> history;
47  std::vector<cv::Rect> faces = face_detector_.findFaces(req.imageFilename,
48  req.fast);
49 
50  for(unsigned int i = 0 ; i < faces.size() ; i++)
51  {
52 
53  unsigned int temp[4];
54  temp[0] = faces[i].x;
55  temp[1] = faces[i].y;
56  temp[2] = faces[i].x + faces[i].width;
57  temp[3] = faces[i].y + faces[i].height;
58 
59  bool duplicate = false;
60  for(unsigned int j = 0 ; j < history.size() ; j++)
61  {
62  if(temp[0] == history[j][0] && temp[1] == history[j][1] &&
63  temp[2] == history[j][2] && temp[3] == history[j][3])
64  {
65  duplicate = true;
66  break;
67  }
68  }
69  if(duplicate)
70  {
71  continue;
72  }
73 
74  geometry_msgs::PointStamped up_left_corner;
75  geometry_msgs::PointStamped down_right_corner;
76 
77  up_left_corner.point.x = temp[0];
78  up_left_corner.point.y = temp[1];
79  down_right_corner.point.x = temp[2];
80  down_right_corner.point.y = temp[3];
81 
82  res.faces_up_left.push_back(up_left_corner);
83  res.faces_down_right.push_back(down_right_corner);
84  }
85 
86  return true;
87 }
ros::ServiceServer faceDetectionService_
ros::NodeHandle nh_
bool faceDetectionCallback(rapp_platform_ros_communications::FaceDetectionRosSrv::Request &req, rapp_platform_ros_communications::FaceDetectionRosSrv::Response &res)
Serves the face detection ROS service callback.
std::vector< cv::Rect > findFaces(std::string file_name, bool fast=false)
Finds faces in an image retrieved from a file URL.
std::string faceDetectionTopic_
FaceDetection(void)
Default constructor.
FaceDetector face_detector_