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>
53#define GETOPTARGS "cdi:o:h"
66void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
67 const std::string &user)
70Read and write PPM images on the disk. Also test exceptions.\n\
73 %s [-i <input image path>] [-o <output image path>]\n\
80 -i <input image path> %s\n\
81 Set image input path.\n\
82 From this path read \"Klimt/Klimt.pgm\"\n\
83 and \"Klimt/Klimt.ppm\" images.\n\
84 Setting the VISP_INPUT_IMAGE_PATH environment\n\
85 variable produces the same behaviour than using\n\
88 -o <output image path> %s\n\
89 Set image output path.\n\
90 From this directory, creates the \"%s\"\n\
91 subdirectory depending on the username, where \n\
92 Klimt_grey.ppm and Klimt_color.ppm output image\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], NULL, ipath, opath, user);
138 usage(argv[0], optarg_, ipath, opath, user);
144 if ((c == 1) || (c == -1)) {
146 usage(argv[0], NULL, ipath, opath, user);
147 std::cerr <<
"ERROR: " << std::endl;
148 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
155int main(
int argc,
const char **argv)
158 std::string env_ipath;
159 std::string opt_ipath;
160 std::string opt_opath;
163 std::string filename;
164 std::string username;
171 if (!env_ipath.empty())
176 opt_opath =
"C:/temp";
185 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
190 if (!opt_ipath.empty())
192 if (!opt_opath.empty())
204 usage(argv[0], NULL, ipath, opt_opath, username);
205 std::cerr << std::endl <<
"ERROR:" << std::endl;
206 std::cerr <<
" Cannot create " << opath << std::endl;
207 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
214 if (!opt_ipath.empty() && !env_ipath.empty()) {
215 if (ipath != env_ipath) {
216 std::cout << std::endl <<
"WARNING: " << std::endl;
217 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
218 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
219 <<
" we skip the environment variable." << std::endl;
224 if (opt_ipath.empty() && env_ipath.empty()) {
225 usage(argv[0], NULL, ipath, opt_opath, username);
226 std::cerr << std::endl <<
"ERROR:" << std::endl;
227 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
228 <<
" environment variable to specify the location of the " << std::endl
229 <<
" image path where test images are located." << std::endl
244 std::cout <<
"Read image: " << filename << std::endl;
248 std::cout <<
"Write image: " << filename << std::endl;
255 std::cout <<
"Read image: " << filename << std::endl;
259 std::cout << e << std::endl;
265 std::cout <<
"Write image: " << filename << std::endl;
268 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
277 std::cout <<
"Read image: " << filename << std::endl;
281 std::cout <<
"Write image: " << filename << std::endl;
288 std::cout <<
"Read image: " << filename << std::endl;
291 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
297 std::cout <<
"Write image: " << filename << std::endl;
300 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
304 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emitted by ViSP classes.
Error that can be emitted by the vpImage class and its derivatives.
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)