/* * Emotions2Plugin * * Author: Andrew Salamon * * Copyright (c) 2008 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. * */ #include "Emotions2Plugin.h" #include #include "PluginController.h" #include "PluginBase.h" #include "SVMPlugin.h" #include "AfterFacePlugin.h" #include "FacePlugin.h" #include "FeaturePlugin.h" #include "CERT_Config.h" #include "CERT_Arguments.h" #include "mp_CERT.h" namespace CERT { Emotions2Plugin::Emotions2Plugin( ConfigItem *_config ) : AfterFacePlugin(_config), auid("com.mpt4u.plugins.FACS_4_4") { std::string w11("emotions2_11.txt"); std::string w8("emotions2_8.txt"); std::string wMore("emotions2_more.txt"); std::string thresh("emotions2_threshold.txt"); std::vector temp = config->getValueForKey( "weights11" ); if( 1 == temp.size() ) w11 = temp[0]; temp.clear(); temp = config->getValueForKey( "weights8" ); if( 1 == temp.size() ) w8 = temp[0]; temp.clear(); temp = config->getValueForKey( "weightsMore" ); if( 1 == temp.size() ) wMore = temp[0]; temp.clear(); temp = config->getValueForKey( "thresholds" ); if( 1 == temp.size() ) thresh = temp[0]; emotions = boost::shared_ptr< mpt::Emotions2 >( new mpt::Emotions2( w11, w8, wMore, thresh ) ); temp = config->getValueForKey( "auid" ); if( 1 == temp.size() ) { auid = temp[0]; } labels = config->getValueForKey( "labels" ); if( labels.size() != mpt::Emotions2::emotionCount ) throw PluginExceptions::configError( "Wrong number of labels in Emotions2 plugin." ); for( unsigned int i = 0; i < labels.size(); ++i ) nans += "\tNaN"; } Emotions2Plugin::~Emotions2Plugin() { } PluginBase * Emotions2Plugin::copy() { return new Emotions2Plugin( *this ); } void Emotions2Plugin::processTask( Task &task ) { results.clear(); if( task.didFindFace ) { for( unsigned int i=0; i < task.faces.size(); ++i ) { FaceWithResults &face = task.faces[i]; PluginResultsType auRes = face.resultsForPlugin( auid ); std::vector auFloat; std::vector addFloat; if( auRes.size() >= (mpt::Emotions2::auCount + mpt::Emotions2::addAuCount) ) { for( unsigned int i = 0; i < mpt::Emotions2::auCount; ++i ) auFloat.push_back( auRes[i] ); for( unsigned int i = mpt::Emotions2::auCount; i < (mpt::Emotions2::auCount + mpt::Emotions2::addAuCount); ++i ) addFloat.push_back( auRes[i] ); } else { PluginResultsType addRes = face.resultsForPlugin( "edu.ucsd.mplab.plugins.AdditionalAUs3" ); auRes = face.resultsForPlugin( "edu.ucsd.mplab.plugins.CERT4_4_Weights" ); if( (auRes.size() == mpt::Emotions2::auCount) && (addRes.size() == mpt::Emotions2::addAuCount) ) { for( unsigned int i = 0; i < auRes.size(); ++i ) auFloat.push_back( auRes[i] ); for( unsigned int i = 0; i < addRes.size(); ++i ) addFloat.push_back( addRes[i] ); } } if( (auFloat.size() == mpt::Emotions2::auCount) && (addFloat.size() == mpt::Emotions2::addAuCount) ) { std::vector more( mpt::Emotions2::moreCount, 0.0 ); std::vector res = emotions->calc( auFloat, addFloat, more ); for( unsigned int i = 0; i < res.size(); ++i ) results.push_back( res[i] ); } face.addResultsForPlugin( id(), results ); } } } bool Emotions2Plugin::areResultsValid() { return results.size() > 0; } double Emotions2Plugin::getResultsDouble() { return 0.0; } } // end namespace CERT