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>
50#define GETOPTARGS "cdi:o:h"
52#ifdef ENABLE_VISP_NAMESPACE
67void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
68 const std::string &user)
71Read and write PGM images on the disk. Also test exceptions.\n\
74 %s [-i <input image path>] [-o <output 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\
85 Setting the VISP_INPUT_IMAGE_PATH environment\n\
86 variable produces the same behaviour than using\n\
89 -o <output image path> %s\n\
90 Set image output path.\n\
91 From this directory, creates the \"%s\"\n\
92 subdirectory depending on the username, where \n\
93 Klimt_grey.pgm output image is written.\n\
97 ipath.c_str(), opath.c_str(), user.c_str());
100 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
115bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
129 usage(argv[0],
nullptr, ipath, opath, user);
137 usage(argv[0], optarg_, ipath, opath, user);
142 if ((c == 1) || (c == -1)) {
144 usage(argv[0],
nullptr, ipath, opath, user);
145 std::cerr <<
"ERROR: " << std::endl;
146 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
153int main(
int argc,
const char **argv)
156 std::string env_ipath;
157 std::string opt_ipath;
158 std::string opt_opath;
162 std::string username;
169 if (!env_ipath.empty())
174 opt_opath =
"C:/temp";
183 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
188 if (!opt_ipath.empty())
190 if (!opt_opath.empty())
203 usage(argv[0],
nullptr, ipath, opt_opath, username);
204 std::cerr << std::endl <<
"ERROR:" << std::endl;
205 std::cerr <<
" Cannot create " << opath << std::endl;
206 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
213 if (!opt_ipath.empty() && !env_ipath.empty()) {
214 if (ipath != env_ipath) {
215 std::cout << std::endl <<
"WARNING: " << std::endl;
216 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
217 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
218 <<
" we skip the environment variable." << std::endl;
223 if (opt_ipath.empty() && env_ipath.empty()) {
224 usage(argv[0],
nullptr, ipath, opt_opath, username);
225 std::cerr << std::endl <<
"ERROR:" << std::endl;
226 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
227 <<
" environment variable to specify the location of the " << std::endl
228 <<
" image path where test images are located." << std::endl
242 std::cout <<
"Read image: " <<
filename << std::endl;
246 std::cout <<
"Write image: " <<
filename << std::endl;
253 std::cout <<
"Read image: " <<
filename << std::endl;
257 std::cout <<
"Catch an exception due to a non existing file: " <<
e << std::endl;
263 std::cout <<
"Write image: " <<
filename << std::endl;
267 std::cout <<
"Catch an exception due to a non existing file: " <<
e << std::endl;
269 std::cout <<
"Test succeed" << std::endl;
273 std::cout <<
"Catch an exception: " <<
e << 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)
static void write(const 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)