34 #include <visp3/core/vpDebug.h>
35 #include <visp3/core/vpImage.h>
36 #include <visp3/core/vpIoTools.h>
37 #include <visp3/io/vpImageIo.h>
38 #include <visp3/io/vpParseArgv.h>
49 #ifdef ENABLE_VISP_NAMESPACE
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\
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\
98 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
112 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
126 usage(argv[0],
nullptr, ipath);
135 usage(argv[0], optarg_, ipath);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0],
nullptr, ipath);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
152 int main(
int argc,
const char **argv)
155 std::string env_ipath;
156 std::string opt_ipath;
157 std::string opt_ppath;
159 std::string filename;
166 if (!env_ipath.empty())
170 if (getOptions(argc, argv, opt_ipath, opt_ppath) ==
false) {
175 if (!opt_ipath.empty())
180 if (!opt_ipath.empty() && !env_ipath.empty()) {
181 if (ipath != env_ipath) {
182 std::cout << std::endl <<
"WARNING: " << std::endl;
183 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
184 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
185 <<
" we skip the environment variable." << std::endl;
199 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 png ok\n");
215 printf(
"Read ppm ok\n");
218 printf(
"Read pgm ok\n");
221 printf(
"Read jpeg ok\n");
224 printf(
"Read png ok\n");
227 filename = opt_ppath;
229 printf(
"Image \"%s\" read successfully\n", filename.c_str());
233 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)