/* * main.cpp * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * * Authors: Andrew Salamon, Josh Susskind * * Please read the disclaimer and notes about redistribution * at the end of this file. * */ #include // for cout and cerr #include #include #include #include #include // For system independent path support #include #include #include // For basename and extension namespace bf = boost::filesystem; #include "rimage.h" #include "ImageDirIterator.h" #include "ImageLoader.h" #include "VideoIterator.h" #include "CERT_Config.h" #include "CERT_Arguments.h" #include "CERT_Loader.h" #include "CERT_Scheduler.h" #include "CERT_Task.h" #include "mp_CERT_Public.h" #include "PluginController.h" #include "AfterFacePlugin.h" #include "FacePlugin.h" #include "SVMPlugin.h" #include "FeaturePlugin.h" std::ostream &mout(); ///< Get an output stream, either cout or a file stream depending on user options. CERT::Config *defaultConfig(); // Default paths to data files std::string defaultFD( "./featuredetector/" ); std::string defaultSVM( "SVMWeights" ); std::string defaultConfigPath( "./CERT.cfg" ); // End Default paths to data files CERT::ImageLoader loader; int main (int argc, char *argv[]) { if( !CERT::Arguments::processArgs( argc, argv, defaultConfigPath ) ) { // We still want to output the verision info std::cout << "CERT v" << MP_CERT_Public::getVersion() << " (build " << MP_CERT_Public::getBuildString() << ")" << std::endl; return -1; } mout() << "CERT v" << MP_CERT_Public::getVersion() << " (build " << MP_CERT_Public::getBuildString() << ")" << std::endl; CERT::PluginController *pc = CERT::PluginController::getPluginController(); CERT::Config *config = defaultConfig(); pc->loadPluginsFromConfig( config ); std::cout << "Loading data files... " << std::endl; std::vector< std::string > paths( CERT::Arguments::paths() ); MP_CERT_Public *cert(NULL); // CERT will load all SVM and Feature plugins from the plugin controller. try { cert = new MP_CERT_Public( false ); } catch( const std::exception &error ) { std::cerr << error.what() << std::endl; return -4; } catch( const std::string error ) { // The feature detector throws strings if there is an error loading data files. std::cerr << error << std::endl; return -2; } std::auto_ptr certDeleter(cert); // make sure cert get's deleted std::cout << "Finished loading data files" << std::endl; // You can either create your own task and use it, or use CERT's internal task. // CERT::Task &task( cert->getTask() ); CERT::Task task; unsigned int pathCount = paths.size(); if( 1 == pathCount ) { task.clear(); task.path = paths[0]; if( loader.loadRImage( task.rimage, task.path ) ) { try { cert->processTask( task ); CERT::Scheduler::postProcessTask( task ); { // Sample code showing how to disable plugins based on their ID CERT::ConfigItem *afectAUconfig = config->itemWithID( "com.mpt4u.plugins.FACS_4_4" ); if( afectAUconfig ) afectAUconfig->setEnabled( false ); else std::cerr << "Unable to get AFECT AU config item." << std::endl; CERT::ConfigItem *lefteye = config->itemWithID( "edu.ucsd.mplab.plugins.features.leftEye" ); if( lefteye ) lefteye->setEnabled( false ); else std::cerr << "Unable to get Left Eye config item." << std::endl; CERT::ConfigItem *glasses = config->itemWithID( "edu.ucsd.mplab.plugins.GlassesDetector" ); if( glasses ) glasses->setEnabled( false ); else std::cerr << "Unable to get Glasses config item." << std::endl; task.clear(); task.path = paths[0]; loader.loadRImage( task.rimage, task.path ); cert->processTask( task ); CERT::Scheduler::postProcessTask( task ); } } catch( std::runtime_error &error ) { mout() << '\t' << error.what() << std::endl; } } } CERT::PluginController::cleanup(); CERT::Arguments::cleanup(); loader.cleanup(); return 0; } std::ostream &mout() { return CERT::Arguments::outputStream(); } void addFeatureToConfig( CERT::Config *configObj, const std::string &id, const std::string &name, const std::string &iname, const std::string &fname ) { CERT::ConfigItem *feature = new CERT::ConfigItem; feature->setPluginID( id ); feature->setName( name ); feature->setInternalName( iname ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + fname + ".fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + fname + ".gpriorxml"), "gprior" ); configObj->addItem( feature ); } CERT::Config *defaultConfig() { CERT::Config *configObj = new CERT::Config; { CERT::ConfigItem *item = new CERT::ConfigItem; item->setPluginID( "com.mpt4u.plugins.FACS_4_4" ); item->setName( "AFECT FACS Codes 4.4" ); item->setInternalName( "FACS_4_4" ); item->setPluginType( "MPT_PluginStep_SVM" ); item->setEnabled( true ); item->setValueForKey( defaultSVM, "dir" ); std::vector labels; labels.push_back( "(AU 1) Inner Brow Raise" ); labels.push_back( "(AU 2) Outer Brow Raise" ); labels.push_back( "(AU 4) Brow Lower" ); labels.push_back( "(AU 5) Eye Widen" ); labels.push_back( "(AU 9) Nose Wrinkle" ); labels.push_back( "(AU 10) Lip Raise" ); labels.push_back( "(AU 12) Lip Corner Pull" ); labels.push_back( "(AU 14) Dimpler" ); labels.push_back( "(AU 15) Lip Corner Depressor" ); labels.push_back( "(AU 17) Chin Raise" ); labels.push_back( "(AU 20) Lip stretch" ); labels.push_back( "(AU 6) Cheek Raise" ); labels.push_back( "(AU 7) Lids Tight" ); labels.push_back( "(AU 18) Lip Pucker" ); labels.push_back( "(AU 23) Lip Tightener" ); labels.push_back( "(AU 24) Lip Presser" ); labels.push_back( "(AU 25) Lips Part" ); labels.push_back( "(AU 26) Jaw Drop" ); labels.push_back( "(AU 28) Lips Suck" ); labels.push_back( "(AU 45) Blink/Eye Closure" ); labels.push_back( "(MLR) Fear Brow" ); labels.push_back( "(MLR) Distress" ); item->setValueForKey( labels, "labels" ); configObj->addItem( item ); } { CERT::ConfigItem *emotion = new CERT::ConfigItem; emotion->setPluginID( "edu.ucsd.mplab.cert.Emotions2" ); emotion->setName( "Basic Emotions 4.4" ); emotion->setInternalName( "emotions2" ); emotion->setPluginType( "MPT_PluginStep_PostProcess" ); emotion->setEnabled( true ); emotion->setDisplay( true ); emotion->setValueForKey( "./emotions2_11.txt", "weights11" ); emotion->setValueForKey( "./emotions2_8.txt", "weights8" ); emotion->setValueForKey( "./emotions2_threshold.txt", "thresholds" ); std::vector emlabels; emlabels.push_back( "Anger" ); emlabels.push_back( "Contempt" ); emlabels.push_back( "Disgust" ); emlabels.push_back( "Fear" ); emlabels.push_back( "Joy" ); emlabels.push_back( "Sad" ); emlabels.push_back( "Surprise" ); emlabels.push_back( "Neutral" ); emotion->setValueForKey( emlabels, "labels" ); configObj->addItem( emotion ); } addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.leftEye", "Left Eye", "left_eye", "left_eye_CERT3" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.rightEye", "Right Eye", "right_eye", "right_eye_CERT3" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.nose", "Nose", "nose", "nose_CERT3" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.mouth", "Mouth", "mouth", "mouth_CERT3_1" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_LeftEye_Nasal", "Left Eye: Nasal", "left_eye_nasal", "left_eye_nasal" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_RightEye_Nasal", "Right Eye: Nasal", "right_eye_nasal", "right_eye_nasal" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_LeftEye_Temporal", "Left Eye: Temporal", "left_eye_temporal", "left_eye_temporal" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_RightEye_Temporal", "Right Eye: Temporal", "right_eye_temporal", "right_eye_temporal" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_Mouth_LeftCorner", "Mouth Left Corner", "mouth_left_corner", "mouth_left_corner" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_Mouth_RightCorner", "Mouth Right Corner", "mouth_right_corner", "mouth_right_corner" ); addFeatureToConfig( configObj, "edu.ucsd.mplab.plugins.features.MPT_Mouth_RightCorner", "Mouth Right Corner", "mouth_right_corner", "mouth_right_corner" ); { CERT::ConfigItem *featureImp = new CERT::ConfigItem; featureImp->setPluginID( "edu.ucsd.mplab.plugins.featureImps.FeatureImprover" ); featureImp->setName( "Feature Improver" ); featureImp->setInternalName( "featureimprover" ); featureImp->setPluginType( "MPT_PluginStep_Features" ); featureImp->setEnabled( true ); featureImp->setDisplay( true ); featureImp->setValueForKey( "", "feature" ); featureImp->setValueForKey( "", "gprior" ); std::vector filabels; filabels.push_back( "Left Eye Imp" ); filabels.push_back( "Right Eye Imp" ); filabels.push_back( "Left Eye Temporal Imp" ); filabels.push_back( "Left Eye Nasal Imp" ); filabels.push_back( "Right Eye Temporal Imp" ); filabels.push_back( "Right Eye Nasal Imp" ); filabels.push_back( "Nose Imp" ); filabels.push_back( "Mouth Imp" ); filabels.push_back( "Mouth Left Corner Imp" ); filabels.push_back( "Mouth Right Corner Imp" ); featureImp->setValueForKey( filabels, "labels" ); configObj->addItem( featureImp ); } CERT::ConfigItem &glob = configObj->getGlobalItem(); glob.setValueForKey( "unconstrained_least_squares", "fdalign" ); CERT::ConfigItem::PropertyType fdproc; std::vector procVec; procVec.push_back( "left_eye_imp" ); procVec.push_back( "left_eye_nasal_imp" ); procVec.push_back( "left_eye_temporal_imp" ); fdproc["left_eye"] = procVec; procVec.clear(); procVec.push_back( "right_eye_imp" ); procVec.push_back( "right_eye_nasal_imp" ); procVec.push_back( "right_eye_temporal_imp" ); fdproc["right_eye"] = procVec; procVec.clear(); procVec.push_back( "nose_imp" ); fdproc["nose"] = procVec; procVec.clear(); procVec.push_back( "mouth_imp" ); procVec.push_back( "mouth_left_corner" ); procVec.push_back( "mouth_right_corner" ); fdproc["mouth"] = procVec; procVec.clear(); glob.setValueForKey( fdproc, "fdproc" ); CERT::ConfigItem *item = new CERT::ConfigItem; std::vector labels; item = new CERT::ConfigItem; item->setPluginID( "standardoutput" ); item->setName( "Standard Output" ); item->setInternalName( "standardoutput" ); item->setPluginType( "MPT_PluginStep_Output" ); item->setEnabled( true ); item->setDisplay( true ); configObj->addItem( item ); item = new CERT::ConfigItem; item->setPluginID( "edu.ucsd.mplab.plugins.SmileDetector" ); item->setName( "Smile Detector" ); item->setInternalName( "smiledetector" ); item->setPluginType( "MPT_PluginStep_AfterFaces" ); item->setEnabled( true ); item->setDisplay( true ); configObj->addItem( item ); item = new CERT::ConfigItem; item->setPluginID( "edu.ucsd.mplab.plugins.GenderDetector" ); item->setName( "Gender Detector" ); item->setInternalName( "genderdetector" ); item->setPluginType( "MPT_PluginStep_AfterFaces" ); item->setEnabled( true ); item->setDisplay( true ); configObj->addItem( item ); item = new CERT::ConfigItem; item->setPluginID( "edu.ucsd.mplab.plugins.GlassesDetector" ); item->setName( "Glasses Detector" ); item->setInternalName( "glassesdetector" ); item->setPluginType( "MPT_PluginStep_AfterFaces" ); item->setEnabled( true ); item->setDisplay( true ); configObj->addItem( item ); item = new CERT::ConfigItem; item->setPluginID( "edu.ucsd.mplab.plugins.PoseDetector" ); item->setName( "Pose Detector" ); item->setInternalName( "posedetector" ); item->setPluginType( "MPT_PluginStep_AfterFaces" ); item->setEnabled( true ); item->setDisplay( true ); labels.clear(); labels.push_back( "Yaw" ); labels.push_back( "Pitch" ); labels.push_back( "Roll" ); item->setValueForKey( labels, "labels" ); configObj->addItem( item ); return configObj; } /* * * 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. * */