/* * Arguments.cpp * * Copyright (c) 2008 Machine Perception Laboratory * University of California San Diego. * * Authors: Andrew Salamon * * Please read the disclaimer and notes about redistribution * at the end of this file. * */ #include #include #include #include #include "CERT_filetypes.h" namespace CERT { /** A class to parse and give access to CERT's command line arguments. * A static singleton is created and accessed through public class member functions. * Call the processArgs method to read all command line arguments before calling any of the individual argument methods. */ class Arguments { public: static bool processArgs( int argc, char *argv[], const std::string &defaultConfigPath = std::string("./CERT.cfg") ); ///< Processes command line arguments. Outputs error messages to standard error and sets the ready flag to false if there are any errors. static void usage( char *name ); static bool ready(); ///< True if arguments have been successfully processed. static void cleanup(); ///< Should be called just before exiting the program. static bool inputIsFaces(); ///< If this is true, faces in input images have have already been found and cropped. static bool sequential(); ///< Set to true if the images are part of a sequence, e.g. video. static bool outputPatches(); ///< If this is set to true, write face patches out to files in patchDir. static std::string patchDir(); ///< Directory where face patch image files will be saved. static int maxTries(); ///< Obsolete. static bool tabDelim(); ///< If true, output will be a simple tab delimited format. static bool outputToFile(); ///< If true, non-error output will go to the specified file rather than standard out. static std::string outputPath(); ///< Path to write non-error output if flag is set. static std::ostream &outputStream(); ///< If outputToFile is true, then stream will be to a file at outputPath, otherwise it will be cout. static std::string configPath(); ///< Path to the configuration file. static const std::vector< std::string > &paths(); ///< A vector of all of the input image files and directories. static Images::filetype patchFiletype(); ///< File format to be used for writing face patch image files. static bool GKRTraining(); ///< True if the GKR plugin should train a model (requires a model path) and write it out to file. static std::string GKRModelPath(); ///< Path to read or write a GKR model. private: static Arguments &getArgs(); private: Arguments(); ~Arguments(); bool _processArgs( int argc, char *argv[], const std::string &defaultConfigPath ); bool getFileArgument( int argc, char *argv[], int &argIndex, std::string &filename, bool writeFlag, const std::string option, const std::string fileTitle, std::string &errorMsg ); void _cleanup(); private: bool _ready; bool _inputIsFaces; bool _sequential; bool _outputPatches; std::string _patchDir; int _maxTries; bool _tabDelim; bool _outputToFile; std::string _outputPath; std::ofstream _outputStream; std::string _configPath; std::string _defaultConfigPath; std::vector< std::string > _paths; Images::filetype _patchFiletype; bool _GKRTraining; std::string _GKRModelPath; }; } /* * * 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. * */