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://mrpt.sourceforge.net/                            |
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         namespace detectors
00045         {
00046                 using namespace mrpt::slam;
00047                 using namespace mrpt::system;
00048                 using namespace mrpt::synch;
00049                 
00050                 /** Specific class for face detection.
00051                   * Methods and variables labeled as experimentals are temporals (for debug or testing
00052                   * purposes) and may disappear in future versions.
00053                   */
00054                 class DETECTORS_IMPEXP CFaceDetection: public CObjectDetection
00055                 {
00056                 public:
00057                 
00058                         CCascadeClassifierDetection cascadeClassifier;
00059 
00060                         CFaceDetection();
00061 
00062                         ~CFaceDetection();
00063 
00064                         virtual void init(const mrpt::utils::CConfigFileBase &cfg );
00065 
00066                         virtual void detectObjects_Impl(const CObservation *obs, vector_detectable_object &detected);
00067                         
00068                         struct TOptions
00069                         {
00070                                 int             confidenceThreshold;
00071                                 bool    multithread;
00072 
00073                                 bool    useCovFilter;
00074                                 bool    useRegionsFilter;
00075                                 bool    useSizeDistanceRelationFilter;
00076                                 bool    useDiagonalDistanceFilter;
00077 
00078                                 bool    batchMode;
00079 
00080                         }m_options;
00081 
00082                         struct TTestsOptions
00083                         {
00084                                 double  planeThreshold;
00085                                 double  planeTest_eigenVal_top;
00086                                 double  planeTest_eigenVal_bottom;
00087                                 double  regionsTest_sumDistThreshold_top;                               
00088                                 double  regionsTest_sumDistThreshold_bottom;                            
00089 
00090                         }m_testsOptions;
00091 
00092                         // Experimental methods
00093                         void experimental_showMeasurements();
00094 
00095                         void debug_returnResults( const vector_uint &falsePositives, const vector_uint &ignore, unsigned int &falsePositivesDeleted, unsigned int &realFacesDeleted );
00096                         
00097                 private:
00098 
00099                         TThreadHandle           m_thread_checkIfFaceRegions;    //!< Thread that execute checkIfFaceRegions filter
00100                         TThreadHandle           m_thread_checkIfFacePlaneCov;   //!< Thread that execute checkIfFacePlaneCov filter
00101                         TThreadHandle           m_thread_checkIfDiagonalSurface;        //!< Thread that execute checkIfDiagonalSurface filter
00102 
00103                         bool    m_checkIfFaceRegions_res;       //!< Save result of checkIfFaceRegions filter
00104                         bool    m_checkIfFacePlaneCov_res;      //!< Save result of checkIfFacePlaneCov filter
00105                         bool    m_checkIfDiagonalSurface_res;   //!< Save result of checkIfDiagonalSurface filter
00106 
00107                         bool    m_end_threads;  //!< Indicates to all threads that must finish their execution
00108                         
00109                         CSemaphore m_enter_checkIfFaceRegions;  //!< Indicates to thread_checkIfFaceRegions that exist a new face to analyze
00110                         CSemaphore m_enter_checkIfFacePlaneCov; //!< Indicates to thread_checkIfFacePlaneCov that exist a new face to analyze
00111                         CSemaphore m_enter_checkIfDiagonalSurface;      //!< Indicates to thread_checkIfDiagonalSurface that exist a new face to analyze
00112 
00113                         CSemaphore m_leave_checkIfFaceRegions;  //!< Indicates to main thread that thread_checkIfFaceRegions has been completed analisis of the last face detected
00114                         CSemaphore m_leave_checkIfFacePlaneCov; //!< Indicates to main thread that thread_checkIfFacePlaneCov has been completed analisis of the last face detected
00115                         CSemaphore m_leave_checkIfDiagonalSurface;      //!< Indicates to main thread that thread_checkIfDiagonalSurface has been completed analisis of the last face detected
00116 
00117                         CObservation3DRangeScan m_lastFaceDetected;     //!< Last face detected
00118 
00119                         struct TMeasurement
00120                         {       
00121                                 bool                    takeMeasures;
00122 
00123                                 vector_double   lessEigenVals;
00124                                 vector_double   errorEstimations;
00125                                 vector_double   meanRegions;
00126 
00127                                 vector_double   sumDistances;
00128 
00129                                 int                             faceNum;
00130                                 vector_uint             deletedRegions;
00131                                 int                             numPossibleFacesDetected;
00132                                 int                             numRealFacesDetected;
00133 
00134                                 bool                    takeTime;
00135 
00136                                 bool                    saveMeasurementsToFile;
00137 
00138                         }m_measure;
00139 
00140                         // To take measures abaout execution time
00141                         CTimeLogger     m_timeLog;
00142 
00143                         std::vector<double> m_meanHist;
00144 
00145 
00146                         // Test to check if a candidate region is a real face
00147 
00148                         bool checkIfFacePlane( CObservation3DRangeScan* face );
00149 
00150                         bool checkIfFacePlaneCov( CObservation3DRangeScan* face );
00151 
00152                         void thread_checkIfFacePlaneCov( );
00153 
00154                         static void dummy_checkIfFacePlaneCov( CFaceDetection *obj );
00155 
00156 
00157                         bool checkIfFaceRegions( CObservation3DRangeScan* face );
00158 
00159                         void thread_checkIfFaceRegions( );
00160 
00161                         static void dummy_checkIfFaceRegions( CFaceDetection *obj );
00162 
00163                         size_t checkRelativePosition( const TPoint3D &p1, const TPoint3D &p2, const TPoint3D &p, double &dist );
00164 
00165 
00166                         void thread_checkIfDiagonalSurface( );
00167 
00168                         bool checkIfDiagonalSurface( CObservation3DRangeScan* face );
00169 
00170                         bool checkIfDiagonalSurface2( CObservation3DRangeScan* face );
00171 
00172                         static void dummy_checkIfDiagonalSurface( CFaceDetection *obj );
00173 
00174                         // Experimental methods to view 3D points
00175 
00176                         void experimental_viewFacePointsScanned( const std::vector<float> &xs, const std::vector<float> &ys, const std::vector<float> &zs );
00177 
00178                         void experimental_viewFacePointsScanned( const CObservation3DRangeScan &face );
00179                         
00180                         void experimental_viewFacePointsScanned( const std::vector<TPoint3D> &points );
00181 
00182                         void experimental_viewFacePointsAndEigenVects(  const std::vector<CArrayDouble<3> > &pointsVector, const CMatrixDouble &eigenVect, const vector_double &eigenVal );
00183 
00184                         void experimental_viewRegions( const std::vector<TPoint3D> regions[9], const TPoint3D meanPos[3][3] );          
00185 
00186                         // Segmentation methods
00187 
00188                         void experimental_segmentFace( const CObservation3DRangeScan &face, CMatrixTemplate<bool> &region );
00189 
00190                         // Histogram methods
00191 
00192                         void experimental_calcHist( const CImage &face, const size_t &c1, const size_t &r1, const size_t &c2, 
00193                                                                                 const size_t &r2, CMatrixTemplate<unsigned int> &hist );
00194 
00195                         
00196 
00197                 }; // End of class
00198         }
00199 
00200 }
00201 
00202 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011