/* * PatchPlugin * * 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 "PatchPlugin.h" #include // For system independent path support //#include #include // For basename and extension namespace bf = boost::filesystem; #include "PluginController.h" #include "CERT_Config.h" #include "CERT_Arguments.h" #include "CERT_filetypes.h" #include "mp_CERT.h" namespace CERT { PatchPlugin::PatchPlugin( ConfigItem *_config ) : AfterFacePlugin(_config) { } PatchPlugin::~PatchPlugin() { } PluginBase * PatchPlugin::copy() { return new PatchPlugin(*this); } std::vector PatchPlugin::getLabels() const { return std::vector(); } void PatchPlugin::processImageUsingCert( RImage &image, MP_CERT &cert ) { if( CERT::Arguments::outputPatches() && !CERT::Arguments::inputIsFaces() && cert.didFindFace() ) { Images::filetype type = CERT::Arguments::patchFiletype(); std::string ext = CERT::Images::extensionFromFiletype( type ); RImage patch = cert.getPatch(); const std::string &path( cert.getLastPath() ); // generate a filename with _face appended. bf::path bfPath( CERT::Arguments::patchDir(), bf::native ); bf::path fname( path, bf::native ); bf::path bname( (bf::basename(fname) + "_face" + ext), bf::native); bfPath /= bname; if( !loader.saveRImage( patch, bfPath.native_file_string(), type ) ) { std::cerr << "Unable to write face to file: " << bfPath.native_file_string() << std::endl; } } } std::string PatchPlugin::id() const { return "edu.ucsd.mplab.plugins.PatchPlugin"; } std::string PatchPlugin::name() const { return "Patch Plugin"; } std::string PatchPlugin::internalName() const { return "patchplugin"; } PluginStep PatchPlugin::step() const { return PluginSteps::Output; } bool PatchPlugin::isEnabled() const { return CERT::Arguments::outputPatches(); } bool PatchPlugin::shouldDisplay() const { return false; } bool PatchPlugin::areResultsValid() { return false; } double PatchPlugin::getResultsDouble() { return 0.0; } } // end namespace CERT