42 #include <visp/vpImage.h>
43 #include <visp/vpImageIo.h>
44 #include <visp/vpIoTools.h>
45 #include <visp/vpParseArgv.h>
46 #include <visp/vpDebug.h>
58 #define GETOPTARGS "i:p:h"
60 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
61 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath);
74 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
77 Read images on the disk.\n\
80 %s [-i <input image path>] [-p <personal 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 .ppm, .jpeg and .png images.\n\
90 Setting the VISP_INPUT_IMAGE_PATH environment\n\
91 variable produces the same behaviour than using\n\
94 -p <personal image path> %s\n\
95 Set personal image path.\n\
96 From this path read the image \"%s\".\n\
100 ipath.c_str(), ppath.c_str(), ppath.c_str());
103 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
117 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
124 case 'i': ipath = optarg_;
break;
125 case 'p': ppath = optarg_;
break;
126 case 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
129 usage(argv[0], optarg_, ipath, ppath);
return false;
break;
133 if ((c == 1) || (c == -1)) {
135 usage(argv[0], NULL, ipath, ppath);
136 std::cerr <<
"ERROR: " << std::endl;
137 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
145 main(
int argc,
const char ** argv)
148 std::string env_ipath;
149 std::string opt_ipath;
150 std::string opt_ppath;
153 std::string filename;
156 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
161 if (! env_ipath.empty())
165 if (getOptions(argc, argv, opt_ipath, opt_ppath) ==
false) {
170 if (!opt_ipath.empty())
172 if (!opt_ppath.empty())
177 if (!opt_ipath.empty() && !env_ipath.empty()) {
178 if (ipath != env_ipath) {
179 std::cout << std::endl
180 <<
"WARNING: " << std::endl;
181 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
182 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
183 <<
" we skip the environment variable." << std::endl;
198 if (opt_ppath.empty())
202 printf(
"Read ppm ok\n");
205 printf(
"Read pgm ok\n");
208 printf(
"Read jpeg ok\n");
211 printf(
"Read jpg ok\n");
214 printf(
"Read png ok\n");
218 printf(
"Read ppm ok\n");
221 printf(
"Read pgm ok\n");
224 printf(
"Read jpeg ok\n");
227 printf(
"Read jpg ok\n");
230 printf(
"Read png ok\n");
234 filename = opt_ppath;
236 vpTRACE(
"image read without problem");
240 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 read(vpImage< unsigned char > &I, const char *filename)