/* * 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; using namespace std; #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; MP_CERT_Public *initializeCERT(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 0;//-1; } mout() << "CERT v" << MP_CERT_Public::getVersion() << " (build " << MP_CERT_Public::getBuildString() << ")" << std::endl; CERT::PluginController *pc = CERT::PluginController::getPluginController(); pc->loadPluginsFromConfig( defaultConfig() ); 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 0;//-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 0;//-2; } //std::auto_ptr certDeleter(cert); // make sure cert get's deleted std::cout << "Finished loading data files" << std::endl; return cert; } void enableComponent(string component_id){ } void disableComponent(string component_id){ } int runCERTOnOneImage (MP_CERT_Public *cert, std::string path) { CERT::Task &task( cert->getTask() ); task.clear(); task.path = path; if( loader.loadRImage( task.rimage, task.path ) ) { try { cert->processTask( task ); CERT::Scheduler::postProcessTask( task ); return 0; } catch( std::runtime_error &error ) { mout() << '\t' << error.what() << std::endl; return -1; } } else { return -1; } } void shutdownCERT(MP_CERT_Public *cert){ // std::auto_ptr certDeleter(cert); // make sure cert get's deleted CERT::PluginController::cleanup(); CERT::Arguments::cleanup(); loader.cleanup(); delete cert; } std::ostream &mout() { return CERT::Arguments::outputStream(); } 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 ); } CERT::ConfigItem *feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.leftEye" ); feature->setName( "Left Eye" ); feature->setInternalName( "left_eye" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "left_eye_CERT3.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "left_eye_CERT3.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.rightEye" ); feature->setName( "Right Eye" ); feature->setInternalName( "right_eye" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "right_eye_CERT3.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "right_eye_CERT3.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.nose" ); feature->setName( "Nose" ); feature->setInternalName( "nose" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "nose_CERT3.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "nose_CERT3.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.mouth" ); feature->setName( "Mouth" ); feature->setInternalName( "mouth" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "mouth_CERT3_1.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "mouth_CERT3_1.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_LeftEye_Nasal" ); feature->setName( "Left Eye: Nasal" ); feature->setInternalName( "left_eye_nasal" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "left_eye_nasal.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "left_eye_nasal.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_RightEye_Nasal" ); feature->setName( "Right Eye: Nasal" ); feature->setInternalName( "right_eye_nasal" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "right_eye_nasal.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "right_eye_nasal.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_LeftEye_Temporal" ); feature->setName( "Left Eye: Temporal" ); feature->setInternalName( "left_eye_temporal" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "left_eye_temporal.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "left_eye_temporal.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_RightEye_Temporal" ); feature->setName( "Right Eye: Temporal" ); feature->setInternalName( "right_eye_temporal" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "right_eye_temporal.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "right_eye_temporal.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_Mouth_LeftCorner" ); feature->setName( "Mouth Left Corner" ); feature->setInternalName( "mouth_left_corner" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "mouth_left_corner.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "mouth_left_corner.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_Mouth_RightCorner" ); feature->setName( "Mouth Right Corner" ); feature->setInternalName( "mouth_right_corner" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "mouth_right_corner.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "mouth_right_corner.gpriorxml"), "gprior" ); configObj->addItem( feature ); feature = new CERT::ConfigItem; feature->setPluginID( "edu.ucsd.mplab.plugins.features.MPT_Mouth_RightCorner" ); feature->setName( "Mouth Right Corner" ); feature->setInternalName( "mouth_right_corner" ); feature->setPluginType( "MPT_PluginStep_Features" ); feature->setEnabled( true ); feature->setDisplay( true ); feature->setValueForKey( (defaultFD + "mouth_right_corner.fdtxml"), "feature" ); feature->setValueForKey( (defaultFD + "mouth_right_corner.gpriorxml"), "gprior" ); configObj->addItem( feature ); { CERT::ConfigItem *featureImp = new CERT::ConfigItem; featureImp->setPluginID( "edu.ucsd.mplab.plugins.featureImps.FeatureImprover" ); featureImp->setName( "Feature Improver" ); featureImp->setInternalName( "featureImpimprover" ); 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" ); item->setValueForKey( filabels, "filabels" ); 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" ); 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. * */