![]() | |
| |
Retrieving Command Line Arguments. The CImg library offers facilities to retrieve command line arguments in a console-based program, as it is a commonly needed operation. Three macros cimg_usage() , cimg_help() and cimg_option() are defined for this purpose. Using these macros allows to easily retrieve options values from the command line. Invoking the compiled executable with the option -h or –help will automatically display the program usage, followed by the list of requested options.The cimg_usage() macroThe macro
The cimg_help() macroThe macro The cimg_option() macroThe macro
Example of useThe code below uses the macros #include "CImg.h" using namespace cimg_library; int main(int argc,char **argv) { cimg_usage("Retrieve command line arguments"); const char* filename = cimg_option("-i","image.gif","Input image file"); const double sigma = cimg_option("-s",1.0,"Standard variation of the gaussian smoothing"); const int nblevels = cimg_option("-n",16,"Number of quantification levels"); const bool hidden = cimg_option("-hidden",false,0); // This is a hidden option CImg<unsigned char> img(filename); img.blur(sigma).quantize(nblevels); if (output) img.save(output); else img.display("Output image"); if (hidden) std::fprintf(stderr,"You found me !\n"); return 0; } Invoking the corresponding executable with ./test -h -hidden -n 20 -i foo.jpg test : Retrieve command line arguments (Oct 16 2004, 12:34:26) -i = foo.jpg : Input image file -o = 0 : Output image file -s = 1 : Standard variation of the gaussian smoothing -n = 20 : Number of quantification levels You found me !
How to learn more about command line options ?You should take a look at the examples |
Copyrights (C) From october 2004, David Tschumperlé - GREYC UMR CNRS 6072, Image team. Copyrights (C) January->September 2004, David Tschumperlé. Copyrights (C) 2000->2003, David Tschumperlé - INRIA Sophia-Antipolis. Odyssée group. |