/* * mp_CERT * * Author: Andrew Salamon * Date: Thu Apr 20 2006 * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef __MP_CERT_H__ #define __MP_CERT_H__ #include #include #include "rimage.h" #include "mp_rotateFace.h" #include "mp_AUResults.h" #include "mp_gabor.h" #include "mp_threadedGabor.h" #include "FeatureAlignment.hpp" #include "PluginController.h" #include "mp_FDEyes.h" namespace CERT { class Task; } /// The pointer to the gabor object might be a threaded subclass, based on the constructor argument. typedef MP_Gabor GABOR_CLASS; /** \brief MP_CERT is a high level wrapper. * It takes an RImage, searches for a face and if it finds one, aligns the face * then calculates AU values. This duplicates most of the functionality of CERT 1.0. * It uses the PluginController to determine which features and/or AUs to detect. * It also uses both the Arguments and Config systems to set various flags. */ class MP_CERT { public: static std::string getVersion(); ///< Returns CERT's version number. static std::string getBuildString(); ///< Returns CERT's build number, more detailed version info. typedef struct { float x; float y; float width; float height; float scale; } certSquare; public: /// MP_CERT constructor. The multiThreaded flag creates a threaded version of the gabor objects, providing a small speed boost on multi-cup systems. MP_CERT( bool multiThreaded = true ); virtual ~MP_CERT(); void loadPlugins(); ///< Load all appropriate plugins (SVM and Features) from the default plugin controller. void processTask( CERT::Task &task ); ///< Not yet implemented. /// Find a face in the image, if found, rotate it and calculate AUs. Run all appropriate plugins afterward. Results can be gotten from the plugins, or from the resultsForCategory method. imagePath may be used by some plugins, but is otherwise not required. void calcAUs( RImage &rimage, const std::string &imagePath = std::string() ); void processNoFace( const std::string &imagePath ); ///< Call this if an image couldn't be read. Not being used, yet. void findFaces( RImage &rimage ); ///< Step 1 /// Assumes a face has already been found and the RImage has been cropped and rotated. The cropping and rotating parameters can have a large effect on AU values, so standard CERT methods should be used to generate the face image. Step 2. void calcAUsFromFace( RImage &face ); bool didFindFace(); ///< Did we find a face in the last image? RImage getPatch() { return patch; } ///< Return a rimage that contains the cropped and rotated face. std::vector eyes(); ///< left.x left.y right.x right.y void clear(); /// Extra categories of SVM weights can be added here. They will be loaded from the given directory. This method should probably be made private since the plugin system now handles deciding which SVM categories should be run. bool addCategoryFromDirectory( std::string cat, const std::string &dir ); std::vector resultsForCategory( const std::string &cat ); ///< Get the results for a particular AU (SVM type plugin only). std::map< std::string, mp_AUResults > getFrequencies(); ///< Full results from the most recent image, including Gabor frequency data (used by some post-processing detectors) ObjectWithFeatures *getLargestFace(); ///< Only valid until next call to calcAUs. CFourCoordinates getCroppedFaceBox(); ///< This is the set of points used to crop and rotate the face. // Methods needed by plugins mp_FDEyes *getFeatureDetector(); void setFaceEstimate( int x, int y, int size, int scale ); certSquare lastFoundFace(); CERT::PluginController &pluginController() { return pc; } /// Set to true if the images are part of a sequence, e.g. video. This option should probably no longer be used. void setSequential( bool seq ) { sequential = seq; } bool getSequential() { return sequential; } /// Used by the feature detector if the sequential flag is set. int getMaxTry(); void setMaxTry( int max ); /// Set the maximum scale that the face finder will search. Set automatically from CERT::Arguments. void setMaxScale( int max ); int getMaxScale(); /// Set the minimum scale that the face finder will search. If a particular application will only be interested in larger faces, setting this to something above zero can speed up the face finding portion of CERT. Set automatically from CERT::Arguments. void setMinScale( int min ); int getMinScale(); bool getInputIsFaces() { return inputIsFaces; } /// If the input images contain only faces that have already been cropped and rotated, then set this flag. Set automatically from CERT::Arguments. void setInputIsFaces( bool _faces ) { inputIsFaces = _faces; } int getNumWindows() { return numWindows; } ///< This is an indication of how much work the face finder did in the last search. const std::string &getLastPath() { return lastPath; } private: certSquare leftEye; certSquare rightEye; certSquare face; RImage patch; MP_RotateFace rotator; mp_FDEyes featureDetector; GABOR_CLASS *gabor; bool foundFace; CERT::PluginController pc; bool sequential; int numWindows; bool inputIsFaces; std::string lastPath; FeatureAlignment::alignment_method alignMethod; /// Must be called before using a cert object if the feature detector is being used. But this is handled by loadPlugins. void loadFeatureDetector(); // Unlike steps 1 and 2, these are private because it doesn't make sense to call them except as part of the whole process. bool getPatchWithFeatures( RImage &rimage ); ///< Step 3. void doAfterFacePlugins( RImage &rimage ); ///< Step 4. void doResultsPlugins( RImage &rimage ); ///< Step 5. void clearSVMPlugins(); }; #endif