36 #include <visp3/core/vpDebug.h>
37 #include <visp3/core/vpImage.h>
38 #include <visp3/core/vpIoTools.h>
39 #include <visp3/io/vpImageIo.h>
40 #include <visp3/io/vpParseArgv.h>
52 #define GETOPTARGS "cdi:p:h"
54 void usage(
const char *name,
const char *badparam, std::string ipath);
55 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath);
66 void usage(
const char *name,
const char *badparam, std::string ipath)
69 Read images on the disk.\n\
72 %s [-i <input image path>] [-p <personal image path>]\n\
79 -i <input image path> %s\n\
80 Set image input path.\n\
81 From this path read \"Klimt/Klimt.pgm,\n\
82 .ppm, .jpeg and .png images.\n\
83 Setting the VISP_INPUT_IMAGE_PATH environment\n\
84 variable produces the same behaviour than using\n\
87 -p <personal image path> \n\
88 Path to an image used to test image reading function.\n\
89 Example: -p /my_path_to/image.png\n\
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
110 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
124 usage(argv[0],
nullptr, ipath);
133 usage(argv[0], optarg_, ipath);
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0],
nullptr, ipath);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
150 int main(
int argc,
const char **argv)
153 std::string env_ipath;
154 std::string opt_ipath;
155 std::string opt_ppath;
157 std::string filename;
164 if (!env_ipath.empty())
168 if (getOptions(argc, argv, opt_ipath, opt_ppath) ==
false) {
173 if (!opt_ipath.empty())
178 if (!opt_ipath.empty() && !env_ipath.empty()) {
179 if (ipath != env_ipath) {
180 std::cout << std::endl <<
"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;
197 if (opt_ppath.empty()) {
200 printf(
"Read ppm ok\n");
203 printf(
"Read pgm ok\n");
206 printf(
"Read jpeg ok\n");
209 printf(
"Read png ok\n");
213 printf(
"Read ppm ok\n");
216 printf(
"Read pgm ok\n");
219 printf(
"Read jpeg ok\n");
222 printf(
"Read png ok\n");
224 filename = opt_ppath;
226 printf(
"Image \"%s\" read successfully\n", filename.c_str());
229 std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;
error that can be emitted by ViSP classes.
const char * getMessage() const
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)