faces.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Face-specific computer vision algorithms.
00003 *
00004 **********************************************************************
00005 *
00006 * Software License Agreement (BSD License)
00007 * 
00008 *  Copyright (c) 2008, Willow Garage, Inc.
00009 *  All rights reserved.
00010 * 
00011 *  Redistribution and use in source and binary forms, with or without
00012 *  modification, are permitted provided that the following conditions
00013 *  are met:
00014 * 
00015 *   * Redistributions of source code must retain the above copyright
00016 *     notice, this list of conditions and the following disclaimer.
00017 *   * Redistributions in binary form must reproduce the above
00018 *     copyright notice, this list of conditions and the following
00019 *     disclaimer in the documentation and/or other materials provided
00020 *     with the distribution.
00021 *   * Neither the name of the Willow Garage nor the names of its
00022 *     contributors may be used to endorse or promote products derived
00023 *     from this software without specific prior written permission.
00024 * 
00025 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00028 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00029 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00030 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00031 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00032 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00034 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036 *  POSSIBILITY OF SUCH DAMAGE.
00037 *********************************************************************/
00038 
00039 /* Author: Caroline Pantofaru */
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 <ros/console.h>
00057 #include <boost/thread/mutex.hpp>
00058 #include <boost/bind.hpp>
00059 #include <boost/thread/thread.hpp>
00060 #include <boost/thread/condition.hpp>
00061 
00062 
00063 using namespace std;
00064 
00065 
00066 namespace people {
00067 
00068 
00072 struct Box2D3D {
00073   cv::Point2d center2d;
00074   cv::Point3d center3d;
00075   double width2d;
00076   double width3d;
00077   cv::Rect box2d;
00078   string status;
00079   int id;
00080 };
00081 
00082 
00086 struct Face {
00087   string id;
00088   string name; 
00089 };
00090 
00091 
00096 class Faces
00097 {
00098  public:
00099 
00100   // Default thresholds for the face detection algorithm.
00101   static const double FACE_SIZE_MIN_M=0.1; 
00102   static const double FACE_SIZE_MAX_M=0.5; 
00103   static const double MAX_FACE_Z_M=8.0; 
00104   // Default thresholds for face tracking.
00105   static const double FACE_SEP_DIST_M=1.0; 
00107   // Thresholds for the face detection algorithm.
00108   double face_size_min_m_; 
00109   double face_size_max_m_; 
00110   double max_face_z_m_; 
00111   // Thresholds for face tracking.
00112   double face_sep_dist_m_; 
00116   // Create an empty list of people.
00117   Faces();
00118 
00119   // Destroy a list of people.
00120   ~Faces();
00121 
00122 
00135   vector<Box2D3D> detectAllFacesDisparity(const cv::Mat &image, double threshold, const cv::Mat &disparity_image, image_geometry::StereoCameraModel *cam_model);
00136 
00149   vector<Box2D3D> detectAllFacesDepth(const cv::Mat &image, double threshold, const cv::Mat &depth_image, image_geometry::StereoCameraModel *cam_model);
00150 
00159   void initFaceDetectionDisparity(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);
00160 
00161 
00170   void initFaceDetectionDepth(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);
00171 
00173  private:
00174 
00175   vector<Face> list_;  
00176   vector<Box2D3D> faces_; 
00178   cv::Mat cv_image_gray_;  
00179   cv::Mat const* disparity_image_; 
00180   cv::Mat const* depth_image_; 
00181   image_geometry::StereoCameraModel *cam_model_; 
00183   boost::mutex face_mutex_, face_done_mutex_, t_mutex_; 
00184   boost::mutex* face_go_mutex_;
00185   boost::thread_group threads_;
00186   boost::condition face_detection_ready_cond_, face_detection_done_cond_; 
00187   int num_threads_to_wait_for_;
00188   int images_ready_;
00189 
00190   /* Structures for the face detector. */
00191   cv::CascadeClassifier cascade_;  
00193   void faceDetectionThreadDisparity(uint i);
00194   void faceDetectionThreadDepth(uint i);
00195 
00196 };
00197 
00198 };
00199 
00200 #endif
00201 


face_detector
Author(s): Caroline Pantofaru
autogenerated on Thu Jan 2 2014 11:35:05