39 #include <visp3/core/vpImage.h>
40 #include <visp3/io/vpImageIo.h>
41 #include <visp3/io/vpParseArgv.h>
42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/core/vpDebug.h>
55 #define GETOPTARGS "cdi:o:h"
57 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
58 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
71 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
74 Read and write PGM images on the disk. Also test exceptions.\n\
77 %s [-i <input image path>] [-o <output image path>]\n\
83 -i <input image path> %s\n\
84 Set image input path.\n\
85 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
87 Setting the VISP_INPUT_IMAGE_PATH environment\n\
88 variable produces the same behaviour than using\n\
91 -o <output image path> %s\n\
92 Set image output path.\n\
93 From this directory, creates the \"%s\"\n\
94 subdirectory depending on the username, where \n\
95 Klimt_grey.pgm output image is written.\n\
99 ipath.c_str(), opath.c_str(), user.c_str());
102 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
117 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
124 case 'i': ipath = optarg_;
break;
125 case 'o': opath = optarg_;
break;
126 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
133 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
137 if ((c == 1) || (c == -1)) {
139 usage(argv[0], NULL, ipath, opath, user);
140 std::cerr <<
"ERROR: " << std::endl;
141 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
149 main(
int argc,
const char ** argv)
152 std::string env_ipath;
153 std::string opt_ipath;
154 std::string opt_opath;
157 std::string filename;
158 std::string username;
164 if (! env_ipath.empty())
169 opt_opath =
"C:/temp";
178 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
183 if (!opt_ipath.empty())
185 if (!opt_opath.empty())
198 usage(argv[0], NULL, ipath, opt_opath, username);
199 std::cerr << std::endl
200 <<
"ERROR:" << std::endl;
201 std::cerr <<
" Cannot create " << opath << std::endl;
202 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
209 if (!opt_ipath.empty() && !env_ipath.empty()) {
210 if (ipath != env_ipath) {
211 std::cout << std::endl
212 <<
"WARNING: " << std::endl;
213 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
214 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
215 <<
" we skip the environment variable." << std::endl;
220 if (opt_ipath.empty() && env_ipath.empty()){
221 usage(argv[0], NULL, ipath, opt_opath, username);
222 std::cerr << std::endl
223 <<
"ERROR:" << std::endl;
224 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
226 <<
" environment variable to specify the location of the " << std::endl
227 <<
" image path where test images are located." << std::endl << std::endl;
240 std::cout <<
"Read image: " << filename << std::endl;
244 std::cout <<
"Write image: " << filename << std::endl;
251 std::cout <<
"Read image: " << filename << std::endl;
255 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
261 std::cout <<
"Write image: " << filename << std::endl;
265 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
270 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
static void read(vpImage< unsigned char > &I, const std::string &filename)