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"
56void usage(
const char *name,
const char *badparam, std::string ipath);
57bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath);
68void usage(
const char *name,
const char *badparam, std::string ipath)
71Read 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);
112bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath)
126 usage(argv[0],
nullptr, ipath);
134 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;
150int main(
int argc,
const char **argv)
153 std::string env_ipath;
154 std::string opt_ipath;
155 std::string opt_ppath;
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");
227 printf(
"Image \"%s\" read successfully\n",
filename.c_str());
231 std::cout <<
"Catch an exception: " <<
e.getMessage() << std::endl;
error that can be emitted by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)