39 #include <visp3/core/vpDebug.h>
40 #include <visp3/core/vpImage.h>
41 #include <visp3/core/vpIoTools.h>
42 #include <visp3/io/vpImageIo.h>
43 #include <visp3/io/vpParseArgv.h>
55 #define GETOPTARGS "cdi:p:h"
57 void usage(
const char *name,
const char *badparam, std::string ipath);
58 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath);
69 void usage(
const char *name,
const char *badparam, std::string ipath)
72 Read images on the disk.\n\
75 %s [-i <input image path>] [-p <personal image path>]\n\
81 -i <input image path> %s\n\
82 Set image input path.\n\
83 From this path read \"Klimt/Klimt.pgm,\n\
84 .ppm, .jpeg and .png images.\n\
85 Setting the VISP_INPUT_IMAGE_PATH environment\n\
86 variable produces the same behaviour than using\n\
89 -p <personal image path> \n\
90 Path to an image used to test image reading function.\n\
91 Example: -p /my_path_to/image.png\n\
94 Print the help.\n\n", ipath.c_str());
97 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
111 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
125 usage(argv[0], NULL, ipath);
134 usage(argv[0], optarg_, ipath);
140 if ((c == 1) || (c == -1)) {
142 usage(argv[0], NULL, ipath);
143 std::cerr <<
"ERROR: " << std::endl;
144 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151 int main(
int argc,
const char **argv)
154 std::string env_ipath;
155 std::string opt_ipath;
156 std::string opt_ppath;
158 std::string filename;
165 if (!env_ipath.empty())
169 if (getOptions(argc, argv, opt_ipath, opt_ppath) ==
false) {
174 if (!opt_ipath.empty())
179 if (!opt_ipath.empty() && !env_ipath.empty()) {
180 if (ipath != env_ipath) {
181 std::cout << std::endl <<
"WARNING: " << std::endl;
182 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
183 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
184 <<
" we skip the environment variable." << std::endl;
198 if (opt_ppath.empty()) {
201 printf(
"Read ppm ok\n");
204 printf(
"Read pgm ok\n");
207 printf(
"Read jpeg ok\n");
210 printf(
"Read png ok\n");
214 printf(
"Read ppm ok\n");
217 printf(
"Read pgm ok\n");
220 printf(
"Read jpeg ok\n");
223 printf(
"Read png ok\n");
225 filename = opt_ppath;
227 printf(
"Image \"%s\" read successfully\n", filename.c_str());
230 std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;