38 #include <visp3/core/vpImage.h>
39 #include <visp3/io/vpImageIo.h>
40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/io/vpParseArgv.h>
42 #include <visp3/core/vpDebug.h>
54 #define GETOPTARGS "cdi:p:h"
56 void usage(
const char *name,
const char *badparam, std::string ipath);
57 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath);
68 void usage(
const char *name,
const char *badparam, std::string ipath)
71 Read images on the disk.\n\
74 %s [-i <input image path>] [-p <personal image path>]\n\
80 -i <input image path> %s\n\
81 Set image input path.\n\
82 From this path read \"ViSP-images/Klimt/Klimt.pgm,\n\
83 .ppm, .jpeg and .png images.\n\
84 Setting the VISP_INPUT_IMAGE_PATH environment\n\
85 variable produces the same behaviour than using\n\
88 -p <personal image path> \n\
89 Path to an image used to test image reading function.\n\
90 Example: -p /my_path_to/image.png\n\
97 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
111 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
118 case 'i': ipath = optarg_;
break;
119 case 'p': ppath = optarg_;
break;
120 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
127 usage(argv[0], optarg_, ipath);
return false;
break;
131 if ((c == 1) || (c == -1)) {
133 usage(argv[0], NULL, ipath);
134 std::cerr <<
"ERROR: " << std::endl;
135 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
143 main(
int argc,
const char ** argv)
146 std::string env_ipath;
147 std::string opt_ipath;
148 std::string opt_ppath;
150 std::string filename;
156 if (! env_ipath.empty())
160 if (getOptions(argc, argv, opt_ipath, opt_ppath) ==
false) {
165 if (!opt_ipath.empty())
170 if (!opt_ipath.empty() && !env_ipath.empty()) {
171 if (ipath != env_ipath) {
172 std::cout << std::endl
173 <<
"WARNING: " << std::endl;
174 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
175 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
176 <<
" we skip the environment variable." << std::endl;
191 if (opt_ppath.empty())
195 printf(
"Read ppm ok\n");
198 printf(
"Read pgm ok\n");
201 printf(
"Read jpeg ok\n");
204 printf(
"Read png ok\n");
208 printf(
"Read ppm ok\n");
211 printf(
"Read pgm ok\n");
214 printf(
"Read jpeg ok\n");
217 printf(
"Read png ok\n");
221 filename = opt_ppath;
223 printf(
"Image \"%s\" read successfully\n", filename.c_str());
227 std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
const char * getMessage(void) const
static void read(vpImage< unsigned char > &I, const std::string &filename)