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>
56 #define GETOPTARGS "cdi:o:h"
58 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
59 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
72 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
75 Read and write PPM images on the disk. Also test exceptions.\n\
78 %s [-i <input image path>] [-o <output image path>]\n\
84 -i <input image path> %s\n\
85 Set image input path.\n\
86 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
87 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
88 Setting the VISP_INPUT_IMAGE_PATH environment\n\
89 variable produces the same behaviour than using\n\
92 -o <output image path> %s\n\
93 Set image output path.\n\
94 From this directory, creates the \"%s\"\n\
95 subdirectory depending on the username, where \n\
96 Klimt_grey.ppm and Klimt_color.ppm output image\n\
100 Print the help.\n\n",
101 ipath.c_str(), opath.c_str(), user.c_str());
104 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
119 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
126 case 'i': ipath = optarg_;
break;
127 case 'o': opath = optarg_;
break;
128 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
135 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0], NULL, ipath, opath, user);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151 main(
int argc,
const char ** argv)
154 std::string env_ipath;
155 std::string opt_ipath;
156 std::string opt_opath;
159 std::string filename;
160 std::string username;
166 if (! env_ipath.empty())
171 opt_opath =
"C:/temp";
180 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
185 if (!opt_ipath.empty())
187 if (!opt_opath.empty())
200 usage(argv[0], NULL, ipath, opt_opath, username);
201 std::cerr << std::endl
202 <<
"ERROR:" << std::endl;
203 std::cerr <<
" Cannot create " << opath << std::endl;
204 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
211 if (!opt_ipath.empty() && !env_ipath.empty()) {
212 if (ipath != env_ipath) {
213 std::cout << std::endl
214 <<
"WARNING: " << std::endl;
215 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
216 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
217 <<
" we skip the environment variable." << std::endl;
222 if (opt_ipath.empty() && env_ipath.empty()){
223 usage(argv[0], NULL, ipath, opt_opath, username);
224 std::cerr << std::endl
225 <<
"ERROR:" << std::endl;
226 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
228 <<
" environment variable to specify the location of the " << std::endl
229 <<
" image path where test images are located." << std::endl << std::endl;
243 std::cout <<
"Read image: " << filename << std::endl;
247 std::cout <<
"Write image: " << filename << std::endl;
255 std::cout <<
"Read image: " << filename << std::endl;
261 std::cout << e << std::endl ;
267 std::cout <<
"Write image: " << filename << std::endl;
271 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
280 std::cout <<
"Read image: " << filename << std::endl;
284 std::cout <<
"Write image: " << filename << std::endl;
291 std::cout <<
"Read image: " << filename << std::endl;
295 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
301 std::cout <<
"Write image: " << filename << std::endl;
305 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
310 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emited by ViSP classes.
Error that can be emited by the vpImage class and its derivates.
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)