40 #include <visp3/core/vpDebug.h> 41 #include <visp3/core/vpImage.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/io/vpImageIo.h> 44 #include <visp3/io/vpParseArgv.h> 57 #define GETOPTARGS "cdi:o:h" 70 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
71 const std::string &user)
74 Read and write PPM images on the disk. Also test exceptions.\n\ 77 %s [-i <input image path>] [-o <output image path>]\n\ 83 -i <input image path> %s\n\ 84 Set image input path.\n\ 85 From this path read \"Klimt/Klimt.pgm\"\n\ 86 and \"Klimt/Klimt.ppm\" images.\n\ 87 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 88 variable produces the same behaviour than using\n\ 91 -o <output image path> %s\n\ 92 Set image output path.\n\ 93 From this directory, creates the \"%s\"\n\ 94 subdirectory depending on the username, where \n\ 95 Klimt_grey.ppm and Klimt_color.ppm output image\n\ 99 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
102 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
117 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
131 usage(argv[0], NULL, ipath, opath, user);
140 usage(argv[0], optarg_, ipath, opath, user);
146 if ((c == 1) || (c == -1)) {
148 usage(argv[0], NULL, ipath, opath, user);
149 std::cerr <<
"ERROR: " << std::endl;
150 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
157 int main(
int argc,
const char **argv)
160 std::string env_ipath;
161 std::string opt_ipath;
162 std::string opt_opath;
165 std::string filename;
166 std::string username;
173 if (!env_ipath.empty())
178 opt_opath =
"C:/temp";
187 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
192 if (!opt_ipath.empty())
194 if (!opt_opath.empty())
206 usage(argv[0], NULL, ipath, opt_opath, username);
207 std::cerr << std::endl <<
"ERROR:" << std::endl;
208 std::cerr <<
" Cannot create " << opath << std::endl;
209 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
216 if (!opt_ipath.empty() && !env_ipath.empty()) {
217 if (ipath != env_ipath) {
218 std::cout << std::endl <<
"WARNING: " << std::endl;
219 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 220 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
221 <<
" we skip the environment variable." << std::endl;
226 if (opt_ipath.empty() && env_ipath.empty()) {
227 usage(argv[0], NULL, ipath, opt_opath, username);
228 std::cerr << std::endl <<
"ERROR:" << std::endl;
229 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
230 <<
" environment variable to specify the location of the " << std::endl
231 <<
" image path where test images are located." << std::endl
246 std::cout <<
"Read image: " << filename << std::endl;
250 std::cout <<
"Write image: " << filename << std::endl;
257 std::cout <<
"Read image: " << filename << std::endl;
261 std::cout << e << std::endl;
267 std::cout <<
"Write image: " << filename << std::endl;
270 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
279 std::cout <<
"Read image: " << filename << std::endl;
283 std::cout <<
"Write image: " << filename << std::endl;
290 std::cout <<
"Read image: " << filename << std::endl;
293 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
299 std::cout <<
"Write image: " << filename << std::endl;
302 std::cout <<
"Catch an exception due to a non existing file: " << e << std::endl;
306 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emited by ViSP classes.
Error that can be emited by the vpImage class and its derivates.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
static void read(vpImage< unsigned char > &I, const std::string &filename)