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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef FACES_H
00042 #define FACES_H
00043
00044
00045
00046 #include <stdio.h>
00047 #include <iostream>
00048 #include <vector>
00049
00050 #include <opencv/cv.hpp>
00051 #include <opencv/cxcore.hpp>
00052 #include <opencv/cvaux.hpp>
00053
00054 #include "image_geometry/stereo_camera_model.h"
00055 #include "ros/time.h"
00056 #include <boost/thread/mutex.hpp>
00057 #include <boost/bind.hpp>
00058 #include <boost/thread/thread.hpp>
00059 #include <boost/thread/condition.hpp>
00060
00061
00062 using namespace std;
00063
00064
00065 namespace people {
00066
00067
00071 struct Box2D3D {
00072 cv::Point2d center2d;
00073 cv::Point3d center3d;
00074 double radius2d;
00075 double radius3d;
00076 cv::Rect box2d;
00077 string status;
00078 int id;
00079 };
00080
00081
00085 struct Face {
00086 string id;
00087 string name;
00088 };
00089
00090
00095 class Faces
00096 {
00097 public:
00098
00099
00100 static const double FACE_SIZE_MIN_M=0.1;
00101 static const double FACE_SIZE_MAX_M=0.5;
00102 static const double MAX_FACE_Z_M=8.0;
00103
00104 static const double FACE_SEP_DIST_M=1.0;
00106
00107 double face_size_min_m_;
00108 double face_size_max_m_;
00109 double max_face_z_m_;
00110
00111 double face_sep_dist_m_;
00115
00116 Faces();
00117
00118
00119 ~Faces();
00120
00121
00134 vector<Box2D3D> detectAllFaces(cv::Mat &image, double threshold, cv::Mat &disparity_image, image_geometry::StereoCameraModel *cam_model);
00135
00144 void initFaceDetection(uint num_cascades, string haar_classifier_filename, double face_size_min_m, double face_size_max_m, double max_face_z_m, double face_sep_dist_m);
00145
00147 private:
00148
00149 vector<Face> list_;
00150 vector<Box2D3D> faces_;
00152 cv::Mat cv_image_gray_;
00153 cv::Mat *disparity_image_;
00154 image_geometry::StereoCameraModel *cam_model_;
00156 boost::mutex face_mutex_, face_done_mutex_, t_mutex_;
00157 boost::mutex* face_go_mutex_;
00158 boost::thread_group threads_;
00159 boost::condition face_detection_ready_cond_, face_detection_done_cond_;
00160 int num_threads_to_wait_for_;
00161 int images_ready_;
00162
00163
00164 cv::CascadeClassifier cascade_;
00166 void faceDetectionThread(uint i);
00167
00168 };
00169
00170 };
00171
00172 #endif
00173