/* * IntervalCRP * * 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 "IntervalCRP.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" #include "crp.h" #include "tt.h" namespace CERT { IntervalCRP::IntervalCRP( ConfigItem *_config ) : AfterFacePlugin(_config), window(200), m(2), t(12), e(1.5) { if( config->hasIntValueForKey( "m" ) ) m = config->getIntValueForKey( "m" ); if( config->hasIntValueForKey( "t" ) ) t = config->getIntValueForKey( "t" ); if( config->hasFloatValueForKey( "e" ) ) e = config->getFloatValueForKey( "e" ); if( config->hasFloatValueForKey( "interval" ) ) window = config->getFloatValueForKey( "interval" ); labels = config->getValueForKey( "labels" ); for( unsigned int i = 0; i < labels.size(); ++i ) nans += "\tNaN"; } IntervalCRP::~IntervalCRP() { } PluginBase * IntervalCRP::copy() { return new IntervalCRP(*this); } void IntervalCRP::processImageUsingCert( RImage &image, MP_CERT &cert ) { PluginController *pc = &cert.pluginController(); results.clear(); if( !cert.didFindFace() ) return; // These plugin id's should be in the config file PluginBase *auPlugin = pc->pluginWithID( "edu.ucsd.mplab.plugins.CERT4_4_Weights" ); if( auPlugin ) { PluginResultsType auRes = auPlugin->getResults(); if( storage.size() == 0 ) { storage.resize( auRes.size() ); } unsigned int ind = 0; for( ind = 0; ind < auRes.size(); ++ind ) { // subtract the oldest value (if more than window values) from the running total // remove the oldest value (if more than window values) // add the new value to the running total // add the new value to the storage deque std::deque &ref = storage[ind]; ref.push_front( auRes[ind] ); // if( ref.size() >= window ) { if( ref.size() >= window ) ref.pop_back(); boost::multi_array< float, 2> s; std::vector x( ref.size(), 0.0 ); std::copy ( ref.begin(), ref.end(), x.begin() ); if( crp( m, t, e, x, s ) ) { float v = -9997; std::vector v_dist; if( tt( s, v, v_dist ) ) { // copy to results results.push_back( v ); } else { results.push_back( -9998 ); // probably ought to be NaN } } else { results.push_back( -9999 ); // probably ought to be NaN } } } } } //void //IntervalCRP::processTask( Task &task ) //{ // results.clear(); // // if( task.didFindFace ) // { // PluginResultsType auRes = task.resultsForPlugin( "edu.ucsd.mplab.plugins.CERT4_4_Weights" ); // // if( auRes.size() > 0 ) // { // if( storage.size() == 0 ) // { // storage.resize( auRes.size() ); // } // // unsigned int ind = 0; // for( ind = 0; ind < auRes.size(); ++ind ) // { // // subtract the oldest value (if more than window values) from the running total // // remove the oldest value (if more than window values) // // add the new value to the running total // // add the new value to the storage deque // std::deque &ref = storage[ind]; // ref.push_front( auRes[ind] ); // // // if( ref.size() >= window ) // { // if( ref.size() >= window ) // ref.pop_back(); // if( ref.size() > 0 ) // { // boost::multi_array< float, 2> s; // std::vector x( ref.size(), 0.0 ); // // I could get around this need to copy ref by having crp take a pair of iterators // std::copy ( ref.begin(), ref.end(), x.begin() ); // if( crp( m, t, e, x, s ) ) // { // float v(-9997); // std::vector v_dist; // if( tt( s, v, v_dist ) ) // { // // copy to results // results.push_back( v ); // } // else // { // results.push_back( -9998 ); // probably ought to be NaN // } // } // else // { // results.push_back( -9999 ); // probably ought to be NaN // } // // task.addResultsForPlugin( id(), results ); // } // } // } // } // } //} bool IntervalCRP::areResultsValid() { return results.size() > 0; } double IntervalCRP::getResultsDouble() { return 0.0; } } // end namespace CERT