icub-client
faceTracker.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4 * Copyright (C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
5 * Authors: Hyung Jin Chang
6 * email: hj.chang@imperial.ac.uk
7 * website: http://wysiwyd.upf.edu/
8 * Permission is granted to copy, distribute, and/or modify this program
9 * under the terms of the GNU General Public License, version 2 or any
10 * later version published by the Free Software Foundation.
11 *
12 * A copy of the license can be found at
13 * icub-client/license/gpl.txt
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details
19 */
20 
21 #ifndef _FACETRACKER_MODULE_H_
22 #define _FACETRACKER_MODULE_H_
23 
24 #include <cstdio>
25 #include <iostream>
26 #include <ctime>
27 #include <cmath>
28 
29 #include <opencv2/opencv.hpp>
30 
31 #include <yarp/os/all.h>
32 #include <yarp/sig/all.h>
33 #include <yarp/dev/all.h>
34 
38 class faceTrackerModule : public yarp::os::RFModule {
39  yarp::os::RpcServer handlerPort;
40  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > imagePortLeft;
41 
42  yarp::dev::IVelocityControl *vel;
43  yarp::dev::IEncoders *enc;
44 
45  yarp::dev::PolyDriver *robotHead;
46 
47  yarp::sig::VectorOf<double> velocity_command;
48  yarp::sig::VectorOf<double> cur_encoders;
49 
50  yarp::dev::IControlMode *ictrl;
51 
52  int getBiggestFaceIdx(const cv::Mat& cvMatImageLeft, const std::vector<cv::Rect> &faces_left);
53 
54 protected:
55  double x_buf;
56  double y_buf;
57 
64 
65  // random motion variables
67  int pan_target;
68  int pan_max;
69  int tilt_max;
70  int nr_jnts;
71 
72  cv::CascadeClassifier face_classifier_left;
73  IplImage *cvIplImageLeft;
74 
78  void moveToDefaultPosition();
79 
83  void faceSearching(bool face_found);
84 
88  void faceTracking(const std::vector<cv::Rect> &faces_left, int biggest_face_left_idx);
89 
90 public:
91 
92  bool configure(yarp::os::ResourceFinder &rf);
93  bool interruptModule();
94  bool close();
95  bool respond(const yarp::os::Bottle& command, yarp::os::Bottle& reply);
96  double getPeriod();
97  bool updateModule();
98 };
99 
100 #endif // __FACETRACKER_MODULE_H__
bool configure(yarp::os::ResourceFinder &rf)
configure all the module parameters and return true if successful
Definition: faceTracker.cpp:29
int setpos_counter
how many iterations have we spend in default position mode
Definition: faceTracker.h:61
bool updateModule()
get an image from the robot&#39;s camera and decide which mode should be chosen next
int nr_jnts
number of joints of the iCub head
Definition: faceTracker.h:70
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
void moveToDefaultPosition()
Move to center position (after being stuck)
cv::CascadeClassifier face_classifier_left
Definition: faceTracker.h:72
int tilt_max
maximum tilt for the iCub
Definition: faceTracker.h:69
int pan_max
maximum pan for the iCub
Definition: faceTracker.h:68
int counter_no_face_found
if in face tracking mode, for how many iterations was no face found
Definition: faceTracker.h:60
int panning_counter
how many times have we spend in face searching mode.
Definition: faceTracker.h:62
void faceSearching(bool face_found)
Randomly move around.
IplImage * cvIplImageLeft
Definition: faceTracker.h:73
int tilt_target
tilt target for face search mode (randomly chosen)
Definition: faceTracker.h:66
int pan_target
pan target for face search mode (randomly chosen)
Definition: faceTracker.h:67
bool close()
close and shut down the module
bool interruptModule()
interrupt the ports
void faceTracking(const std::vector< cv::Rect > &faces_left, int biggest_face_left_idx)
If a face was found, track it.