Main MRPT website > C++ reference
MRPT logo
CFaceDetection.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CFaceDetection_H
00030 #define CFaceDetection_H
00031 
00032 #include <mrpt/detectors/CObjectDetection.h>
00033 #include <mrpt/detectors/CCascadeClassifierDetection.h>
00034 #include <mrpt/utils/CTimeLogger.h>
00035 #include <mrpt/system.h>
00036 #include <mrpt/synch.h>
00037 #include <mrpt/slam/CObservation3DRangeScan.h>
00038 
00039 namespace mrpt
00040 {
00041 
00042         namespace slam { class CObservation3DRangeScan; }
00043 
00044         /** \ingroup mrpt_detectors_grp  */
00045         namespace detectors
00046         {
00047                 using namespace mrpt::slam;
00048                 using namespace mrpt::system;
00049                 using namespace mrpt::synch;
00050                 
00051                 /** Specific class for face detection.
00052                   * Methods and variables labeled as experimentals are temporals (for debug or testing
00053                   * purposes) and may disappear in future versions.
00054                   * \ingroup mrpt_detectors_grp
00055                   */
00056                 class DETECTORS_IMPEXP CFaceDetection: public CObjectDetection
00057                 {
00058                 public:
00059                 
00060                         CCascadeClassifierDetection cascadeClassifier;
00061 
00062                         CFaceDetection();
00063 
00064                         ~CFaceDetection();
00065 
00066                         virtual void init(const mrpt::utils::CConfigFileBase &cfg );
00067 
00068                         virtual void detectObjects_Impl(const CObservation *obs, vector_detectable_object &detected);
00069                         
00070                         struct TOptions
00071                         {
00072                                 int             confidenceThreshold;
00073                                 bool    multithread;
00074 
00075                                 bool    useCovFilter;
00076                                 bool    useRegionsFilter;
00077                                 bool    useSizeDistanceRelationFilter;
00078                                 bool    useDiagonalDistanceFilter;
00079 
00080                                 bool    batchMode;
00081 
00082                         }m_options;
00083 
00084                         struct TTestsOptions
00085                         {
00086                                 double  planeThreshold;
00087                                 double  planeTest_eigenVal_top;
00088                                 double  planeTest_eigenVal_bottom;
00089                                 double  regionsTest_sumDistThreshold_top;                               
00090                                 double  regionsTest_sumDistThreshold_bottom;                            
00091 
00092                         }m_testsOptions;
00093 
00094                         // Experimental methods
00095                         void experimental_showMeasurements();
00096 
00097                         void debug_returnResults( const vector_uint &falsePositives, const vector_uint &ignore, unsigned int &falsePositivesDeleted, unsigned int &realFacesDeleted );
00098                         
00099                 private:
00100 
00101                         TThreadHandle           m_thread_checkIfFaceRegions;    //!< Thread that execute checkIfFaceRegions filter
00102                         TThreadHandle           m_thread_checkIfFacePlaneCov;   //!< Thread that execute checkIfFacePlaneCov filter
00103                         TThreadHandle           m_thread_checkIfDiagonalSurface;        //!< Thread that execute checkIfDiagonalSurface filter
00104 
00105                         bool    m_checkIfFaceRegions_res;       //!< Save result of checkIfFaceRegions filter
00106                         bool    m_checkIfFacePlaneCov_res;      //!< Save result of checkIfFacePlaneCov filter
00107                         bool    m_checkIfDiagonalSurface_res;   //!< Save result of checkIfDiagonalSurface filter
00108 
00109                         bool    m_end_threads;  //!< Indicates to all threads that must finish their execution
00110                         
00111                         CSemaphore m_enter_checkIfFaceRegions;  //!< Indicates to thread_checkIfFaceRegions that exist a new face to analyze
00112                         CSemaphore m_enter_checkIfFacePlaneCov; //!< Indicates to thread_checkIfFacePlaneCov that exist a new face to analyze
00113                         CSemaphore m_enter_checkIfDiagonalSurface;      //!< Indicates to thread_checkIfDiagonalSurface that exist a new face to analyze
00114 
00115                         CSemaphore m_leave_checkIfFaceRegions;  //!< Indicates to main thread that thread_checkIfFaceRegions has been completed analisis of the last face detected
00116                         CSemaphore m_leave_checkIfFacePlaneCov; //!< Indicates to main thread that thread_checkIfFacePlaneCov has been completed analisis of the last face detected
00117                         CSemaphore m_leave_checkIfDiagonalSurface;      //!< Indicates to main thread that thread_checkIfDiagonalSurface has been completed analisis of the last face detected
00118 
00119                         CObservation3DRangeScan m_lastFaceDetected;     //!< Last face detected
00120 
00121                         struct TMeasurement
00122                         {       
00123                                 bool                    takeMeasures;
00124 
00125                                 vector_double   lessEigenVals;
00126                                 vector_double   errorEstimations;
00127                                 vector_double   meanRegions;
00128 
00129                                 vector_double   sumDistances;
00130 
00131                                 int                             faceNum;
00132                                 vector_uint             deletedRegions;
00133                                 int                             numPossibleFacesDetected;
00134                                 int                             numRealFacesDetected;
00135 
00136                                 bool                    takeTime;
00137 
00138                                 bool                    saveMeasurementsToFile;
00139 
00140                         }m_measure;
00141 
00142                         // To take measures abaout execution time
00143                         CTimeLogger     m_timeLog;
00144 
00145                         std::vector<double> m_meanHist;
00146 
00147 
00148                         // Test to check if a candidate region is a real face
00149 
00150                         bool checkIfFacePlane( CObservation3DRangeScan* face );
00151 
00152                         bool checkIfFacePlaneCov( CObservation3DRangeScan* face );
00153 
00154                         void thread_checkIfFacePlaneCov( );
00155 
00156                         static void dummy_checkIfFacePlaneCov( CFaceDetection *obj );
00157 
00158 
00159                         bool checkIfFaceRegions( CObservation3DRangeScan* face );
00160 
00161                         void thread_checkIfFaceRegions( );
00162 
00163                         static void dummy_checkIfFaceRegions( CFaceDetection *obj );
00164 
00165                         size_t checkRelativePosition( const TPoint3D &p1, const TPoint3D &p2, const TPoint3D &p, double &dist );
00166 
00167 
00168                         void thread_checkIfDiagonalSurface( );
00169 
00170                         bool checkIfDiagonalSurface( CObservation3DRangeScan* face );
00171 
00172                         bool checkIfDiagonalSurface2( CObservation3DRangeScan* face );
00173 
00174                         static void dummy_checkIfDiagonalSurface( CFaceDetection *obj );
00175 
00176                         // Experimental methods to view 3D points
00177 
00178                         void experimental_viewFacePointsScanned( const std::vector<float> &xs, const std::vector<float> &ys, const std::vector<float> &zs );
00179 
00180                         void experimental_viewFacePointsScanned( const CObservation3DRangeScan &face );
00181                         
00182                         void experimental_viewFacePointsScanned( const std::vector<TPoint3D> &points );
00183 
00184                         void experimental_viewFacePointsAndEigenVects(  const std::vector<CArrayDouble<3> > &pointsVector, const CMatrixDouble &eigenVect, const vector_double &eigenVal );
00185 
00186                         void experimental_viewRegions( const std::vector<TPoint3D> regions[9], const TPoint3D meanPos[3][3] );          
00187 
00188                         // Segmentation methods
00189 
00190                         void experimental_segmentFace( const CObservation3DRangeScan &face, CMatrixTemplate<bool> &region );
00191 
00192                         // Histogram methods
00193 
00194                         void experimental_calcHist( const CImage &face, const size_t &c1, const size_t &r1, const size_t &c2, 
00195                                                                                 const size_t &r2, CMatrixTemplate<unsigned int> &hist );
00196 
00197                         
00198 
00199                 }; // End of class
00200         }
00201 
00202 }
00203 
00204 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011