/* * 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" #include "CERT_Task.h" /// 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. */ class MP_CERT { public: static std::string getVersion(); static std::string getBuildString(); typedef struct { float x; float y; float width; float height; float scale; } certSquare; public: 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 &getTask() { return task; } /// 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; } 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. bool addCategoryFromDirectory( std::string cat, const std::string &dir ); std::vector resultsForCategory( const std::string &cat ); 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 void setSequential( bool seq ) { sequential = seq; } bool getSequential() { return sequential; } int getMaxTry(); void setMaxTry( int max ); /// The scale methods limit the size of the windows that the face finder will search. void setMaxScale( int max ); int getMaxScale(); void setMinScale( int min ); int getMinScale(); bool getInputIsFaces() { return inputIsFaces; } 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; CERT::Task task; ///< task currently being worked on bool doingTask; /// Must be called before using a cert object if the feature detector is being used. But this is handled by loadPlugins. void loadFeatureDetector(); void collectResults(); ///< Gather all results into the current task object, if there is one. // 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