44#include <visp3/core/vpDebug.h>
45#include <visp3/core/vpImage.h>
46#include <visp3/core/vpImageTools.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/core/vpRect.h>
49#include <visp3/io/vpImageIo.h>
50#include <visp3/io/vpParseArgv.h>
54#ifdef ENABLE_VISP_NAMESPACE
59#define GETOPTARGS "cdi:o:h"
72void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
73 const std::string &user)
76Read an image from the disk (Klimt.pgm), crop a rectangular area\n\
77and save the cropped image on the disk (Klimt_cropped.pgm).\n\
80 %s [-i <input image path>] [-o <output image path>]\n\
87 -i <input image path> %s\n\
88 Set image input path.\n\
89 From this path read \"Klimt/Klimt.pgm\"\n\
91 Setting the VISP_INPUT_IMAGE_PATH environment\n\
92 variable produces the same behaviour than using\n\
95 -o <output image path> %s\n\
96 Set image output path.\n\
97 From this directory, creates the \"%s\"\n\
98 subdirectory depending on the username, where \n\
99 Klimt_cropped.pgm output image is written.\n\
102 Print the help.\n\n",
103 ipath.c_str(), opath.c_str(), user.c_str());
106 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
135 usage(argv[0],
nullptr, ipath, opath, user);
143 usage(argv[0], optarg_, ipath, opath, user);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0],
nullptr, ipath, opath, user);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
159int main(
int argc,
const char **argv)
162 std::string env_ipath;
163 std::string opt_ipath;
164 std::string opt_opath;
168 std::string username;
175 if (!env_ipath.empty())
180 opt_opath =
"C:/temp";
189 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
194 if (!opt_ipath.empty())
196 if (!opt_opath.empty())
209 usage(argv[0],
nullptr, ipath, opt_opath, username);
210 std::cerr << std::endl <<
"ERROR:" << std::endl;
211 std::cerr <<
" Cannot create " << opath << std::endl;
212 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
219 if (opt_ipath.empty()) {
220 if (ipath != env_ipath) {
221 std::cout << std::endl <<
"WARNING: " << std::endl;
222 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
223 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
224 <<
" we skip the environment variable." << std::endl;
229 if (opt_ipath.empty() && env_ipath.empty()) {
230 usage(argv[0],
nullptr, ipath, opt_opath, username);
231 std::cerr << std::endl <<
"ERROR:" << std::endl;
232 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
233 <<
" environment variable to specify the location of the " << std::endl
234 <<
" image path where test images are located." << std::endl
247 std::cout <<
"Read image: " <<
filename << std::endl;
262 std::cout <<
"Write cropped image: " <<
filename << std::endl;
267 std::cout <<
"Catch an exception: " <<
e.getStringMessage() << 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)
Defines a rectangle in the plane.