43 #include <visp/vpImage.h>
44 #include <visp/vpImageIo.h>
45 #include <visp/vpParseArgv.h>
46 #include <visp/vpIoTools.h>
47 #include <visp/vpDebug.h>
60 #define GETOPTARGS "i:o:h"
74 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
77 Read and write PPM images on the disk. Also test exceptions.\n\
80 %s [-i <input image path>] [-o <output image path>]\n\
86 -i <input image path> %s\n\
87 Set image input path.\n\
88 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
89 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
90 Setting the VISP_INPUT_IMAGE_PATH environment\n\
91 variable produces the same behaviour than using\n\
94 -o <output image path> %s\n\
95 Set image output path.\n\
96 From this directory, creates the \"%s\"\n\
97 subdirectory depending on the username, where \n\
98 Klimt_grey.ppm and Klimt_color.ppm output image\n\
102 Print the help.\n\n",
103 ipath.c_str(), opath.c_str(), user.c_str());
106 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121 bool getOptions(
int argc,
const char **argv,
122 std::string &ipath, std::string &opath, std::string user)
129 case 'i': ipath = optarg;
break;
130 case 'o': opath = optarg;
break;
131 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
134 usage(argv[0], optarg, ipath, opath, user);
return false;
break;
138 if ((c == 1) || (c == -1)) {
140 usage(argv[0], NULL, ipath, opath, user);
141 std::cerr <<
"ERROR: " << std::endl;
142 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
150 main(
int argc,
const char ** argv)
153 std::string env_ipath;
154 std::string opt_ipath;
155 std::string opt_opath;
158 std::string filename;
159 std::string username;
162 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
167 if (! env_ipath.empty())
172 opt_opath =
"C:/temp";
181 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
186 if (!opt_ipath.empty())
188 if (!opt_opath.empty())
201 usage(argv[0], NULL, ipath, opt_opath, username);
202 std::cerr << std::endl
203 <<
"ERROR:" << std::endl;
204 std::cerr <<
" Cannot create " << opath << std::endl;
205 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
212 if (!opt_ipath.empty() && !env_ipath.empty()) {
213 if (ipath != env_ipath) {
214 std::cout << std::endl
215 <<
"WARNING: " << std::endl;
216 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
217 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
218 <<
" we skip the environment variable." << std::endl;
223 if (opt_ipath.empty() && env_ipath.empty()){
224 usage(argv[0], NULL, ipath, opt_opath, username);
225 std::cerr << std::endl
226 <<
"ERROR:" << std::endl;
227 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
229 <<
" environment variable to specify the location of the " << std::endl
230 <<
" image path where test images are located." << std::endl << std::endl;
244 std::cout <<
"Read image: " << filename << std::endl;
248 std::cout <<
"Write image: " << filename << std::endl;
255 filename = ipath +
vpIoTools::path(
"/ViSP-images/image-that-does-not-exist.ppm");
256 std::cout <<
"Read image: " << filename << std::endl;
262 std::cout << e << std::endl ;
268 filename = opath +
vpIoTools::path(
"/directory-that-does-not-exist/Klimt.ppm");
269 std::cout <<
"Write image: " << filename << std::endl;
275 std::cout << e << std::endl ;
284 std::cout <<
"Read image: " << filename << std::endl;
288 std::cout <<
"Write image: " << filename << std::endl;
295 filename = ipath +
vpIoTools::path(
"/ViSP-images/image-that-does-not-exist.ppm");
296 std::cout <<
"Read image: " << filename << std::endl;
302 std::cout << e << std::endl ;
308 filename = opath +
vpIoTools::path(
"/directory-that-does-not-exist/Klimt.ppm");
309 std::cout <<
"Write image: " << filename << std::endl;
315 std::cout << e << std::endl ;
static void write(const vpImage< unsigned char > &I, const char *filename)
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 read(vpImage< unsigned char > &I, const char *filename)