?? group__cimg__options.html
字號(hào):
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>The CImg Library - C++ Template Image Processing Library</title> <meta content="David Tschumperle" name="author"> <link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico" /> <link rel="icon" type="image/png" href="favicon.png" /> <style type="text/css" media=screen> <!-- a:active{text-decoration:none; color:#303090} a:link{text-decoration:none; color:#303090} a:visited{text-decoration:none; color:#303090} a:hover{text-decoration:none; color:#4E9F71} --> </style> </head> <body bgcolor="#ffffff" fgcolor="#000000" alink="#ff0000" link="#0000ee" vlink="#551a8b"> <table align="center" border="0" cellpadding="0" cellspacing="0" width="1024"> <tbody> <tr> <td> <hr noshade="noshade" size="1" width="100%"> <center> <a href="http://cimg.sourceforge.net"><img src="../img/CImgLogo2.jpg" border="0"><img src="../img/CImgLogo.jpg" border="0"></a><br> <table style="width: 100%; text-align: left;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top; text-align: right;"><font face="Arial,Helvetica"><big> <b>C++ Template Image Processing Library.</b></big></font></td> <td style="vertical-align: top; text-align: right;"> <a href="http://www.cnrs.fr/"><img src="../img/logoCNRS.gif" border="0"></a> <a href="http://www.greyc.ensicaen.fr/EquipeImage/"><img src="../img/logoGREYC.gif" border="0"></a> <a href="http://www-sop.inria.fr"><img src="../img/logoINRIA.gif" border="0"></a> </td> </tr> </tbody> </table> </center> <hr noshade="noshade" size="1" width="100%"> <center> <table style="width: 100%; text-align: left; margin-left: auto; margin-right: auto; background-color: rgb(238, 238, 255);" border="0" cellpadding="3" cellspacing="0"> <tbody> <tr> <td style="text-align: center; vertical-align: top;"> <font face="Arial,Helvetica" color="#FFFFFF" size="-1"> <b>[</b> <a target="_parent" href="../index.shtml">Introduction</a> <b>]</b>-<b>[</b> <a target="_parent" href="../news.shtml">News</a> <b>]</b>-<b>[</b> <a target="_parent" href="../download.shtml">Download</a> <b>]</b>-<b>[</b> <a target="_parent" href="../screenshots.shtml">Screenshots</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/group__cimg__faq.html">FAQ</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/group__cimg__tutorial.html">Tutorial</a> <b>]</b>-<b>[</b> <a target="_parent" href="../links.shtml">Links</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=334630">Forums-Eng</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=421080">Forums-Fr</a> <b>]</b>-<b>[</b> <a target="_parent" href="../reference/index.html">Reference</a> <b>]</b>-<b>[</b> <a target="_parent" href="http://sourceforge.net/projects/cimg/">SourceForge Repository</a> <b>]</b> </font></td> </tr> </tbody> </table> </center> <hr noshade="noshade" size="1" width="100%"> <noscript> </noscript> </td> </tr> </tbody> </table> </body></html><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> </ul></div><h1>Retrieving Command Line Arguments.</h1><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>The CImg library offers facilities to retrieve command line arguments in a console-based program, as it is a commonly needed operation. Three macros <code>cimg_usage()</code>, <code>cimg_help()</code> and <code>cimg_option()</code> 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 <code>-h</code> or <code>--help</code> will automatically display the program usage, followed by the list of requested options.<h2><a class="anchor" name="so1">The cimg_usage() macro</a></h2>The macro <code>cimg_usage(usage)</code> may be used to describe the program goal and usage. It is generally inserted one time after the <code>int main(int argc,char **argv)</code> definition.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>usage</em> </td><td>: A string describing the program goal and usage. </td></tr> </table></dl><dl class="pre" compact><dt><b>Precondition:</b></dt><dd>The function where <code>cimg_usage()</code> is used must have correctly defined <code>argc</code> and <code>argv</code> variables.</dd></dl><h2><a class="anchor" name="so1_5">The cimg_help() macro</a></h2>The macro <code>cimg_help(str)</code> will display the string <code>str</code> only if the <code>-help</code> or <code>--help</code> option are invoked when running the programm.<h2><a class="anchor" name="so2">The cimg_option() macro</a></h2>The macro <code>cimg_option(name,default,usage)</code> may be used to retrieve an option value from the command line.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>name</em> </td><td>: The name of the option to be retrieved from the command line. </td></tr> <tr><td valign="top"></td><td valign="top"><em>default</em> </td><td>: The default value returned by the macro if no options <code>name</code> has been specified when running the program. </td></tr> <tr><td valign="top"></td><td valign="top"><em>usage</em> </td><td>: A brief explanation of the option. If <code>usage==0</code>, the option won't appear on the option list when invoking the executable with options <code>-h</code> or <code>--help</code> (hidden option).</td></tr> </table></dl><dl class="return" compact><dt><b>Returns:</b></dt><dd><code>cimg_option()</code> returns an object that has the <em>same</em> <em>type</em> than the default value <code>default</code>. The return value is equal to the one specified on the command line. If no such option have been specified, the return value is equal to the default value <code>default</code>. Warning, this can be confusing in some situations (look at the end of the next section). </dd></dl><dl class="pre" compact><dt><b>Precondition:</b></dt><dd>The function where <code>cimg_option()</code> is used must have correctly defined <code>argc</code> and <code>argv</code> variables.</dd></dl><h2><a class="anchor" name="so3">Example of use</a></h2>The code below uses the macros <code>cimg_usage()</code> and <code>cimg_option()</code>. It loads an image, smoothes it an quantifies it with a specified number of values. <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include "CImg.h"</span> <span class="keyword">using namespace </span>cimg_library; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> **argv) { cimg_usage(<span class="stringliteral">"Retrieve command line arguments"</span>); <span class="keyword">const</span> <span class="keywordtype">char</span>* filename = cimg_option(<span class="stringliteral">"-i"</span>,<span class="stringliteral">"image.gif"</span>,<span class="stringliteral">"Input image file"</span>); <span class="keyword">const</span> <span class="keywordtype">char</span>* output = cimg_option(<span class="stringliteral">"-o"</span>,(<span class="keywordtype">char</span>*)0,<span class="stringliteral">"Output image file"</span>); <span class="keyword">const</span> <span class="keywordtype">double</span> sigma = cimg_option(<span class="stringliteral">"-s"</span>,1.0,<span class="stringliteral">"Standard variation of the gaussian smoothing"</span>); <span class="keyword">const</span> <span class="keywordtype">int</span> nblevels = cimg_option(<span class="stringliteral">"-n"</span>,16,<span class="stringliteral">"Number of quantification levels"</span>); <span class="keyword">const</span> <span class="keywordtype">bool</span> hidden = cimg_option(<span class="stringliteral">"-hidden"</span>,<span class="keyword">false</span>,0); <span class="comment">// This is a hidden option</span> CImg<unsigned char> img(filename); img.blur(sigma).quantize(nblevels); <span class="keywordflow">if</span> (output) img.save(output); <span class="keywordflow">else</span> img.display(<span class="stringliteral">"Output image"</span>); <span class="keywordflow">if</span> (hidden) std::fprintf(stderr,<span class="stringliteral">"You found me !\n"</span>); <span class="keywordflow">return</span> 0; }</pre></div><p>Invoking the corresponding executable with <code>test -h -hidden -n 20 -i foo.jpg</code> will display : <div class="fragment"><pre class="fragment"> ./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 !</pre></div><p><dl class="warning" compact><dt><b>Warning:</b></dt><dd>As the type of object returned by the macro <code>cimg_option(option,default,usage)</code> is defined by the type of <code>default</code>, undesired casts may appear when writting code such as : <div class="fragment"><pre class="fragment"> <span class="keyword">const</span> <span class="keywordtype">double</span> sigma = cimg_option(<span class="stringliteral">"-val"</span>,0,<span class="stringliteral">"A floating point value"</span>);</pre></div> In this case, <code>sigma</code> will always be equal to an integer (since the default value <code>0</code> is an integer). When passing a float value on the command line, a <em>float</em> <em>to</em> <em>integer</em> cast is then done, truncating the given parameter to an integer value (this is surely not a desired behavior). You must specify <code>0.0</code> as the default value in this case.</dd></dl><h2><a class="anchor" name="so4">How to learn more about command line options ?</a></h2>You should take a look at the examples <code>examples/inrcast.cpp</code> provided in the CImg Library package. This is a command line based image converter which intensively uses the <code>cimg_option()</code> and <code>cimg_usage()</code> macros to retrieve command line parameters. <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>The CImg Library - C++ Template Image Processing Library</title> <meta content="David Tschumperle" name="author"> <link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico" /> <link rel="icon" type="image/png" href="favicon.png" /> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#ffffff" fgcolor="#000000" alink="#ff0000" link="#0000ee" vlink="#551a8b"> <hr noshade="noshade" size="1" width="100%"> <a href="http://sourceforge.net"> <img src="http://sourceforge.net/sflogo.php?group_id=96492&type=3" border="0" height="37" width="125"></a><!-- Start of StatCounter Code --><script type="text/javascript" language="javascript"><!-- var sc_project=895001; var sc_invisible=1; var sc_partition=7; var sc_security="5ea85181"; //--></script><script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img src="http://c8.statcounter.com/counter.php?sc_project=895001&java=0&security=5ea85181&invisible=1" alt="counter stats" border="0"></a> </noscript><!-- End of StatCounter Code --> </body></html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -