36 #include <visp3/core/vpDebug.h>
37 #include <visp3/core/vpImage.h>
38 #include <visp3/core/vpImageTools.h>
39 #include <visp3/core/vpIoTools.h>
40 #include <visp3/core/vpRect.h>
41 #include <visp3/io/vpImageIo.h>
42 #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 an image from the disk (Klimt.pgm), crop a rectangular area\n\
75 and save the cropped image on the disk (Klimt_cropped.pgm).\n\
78 %s [-i <input image path>] [-o <output image path>]\n\
85 -i <input image path> %s\n\
86 Set image input path.\n\
87 From this path read \"Klimt/Klimt.pgm\"\n\
89 Setting the VISP_INPUT_IMAGE_PATH environment\n\
90 variable produces the same behaviour than using\n\
93 -o <output image path> %s\n\
94 Set image output path.\n\
95 From this directory, creates the \"%s\"\n\
96 subdirectory depending on the username, where \n\
97 Klimt_cropped.pgm output image is written.\n\
100 Print the help.\n\n",
101 ipath.c_str(), opath.c_str(), user.c_str());
104 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
119 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
133 usage(argv[0],
nullptr, ipath, opath, user);
142 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;
159 int main(
int argc,
const char **argv)
162 std::string env_ipath;
163 std::string opt_ipath;
164 std::string opt_opath;
167 std::string filename;
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())
208 usage(argv[0],
nullptr, ipath, opt_opath, username);
209 std::cerr << std::endl <<
"ERROR:" << std::endl;
210 std::cerr <<
" Cannot create " << opath << std::endl;
211 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
218 if (opt_ipath.empty()) {
219 if (ipath != env_ipath) {
220 std::cout << std::endl <<
"WARNING: " << std::endl;
221 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
222 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
223 <<
" we skip the environment variable." << std::endl;
228 if (opt_ipath.empty() && env_ipath.empty()) {
229 usage(argv[0],
nullptr, ipath, opt_opath, username);
230 std::cerr << std::endl <<
"ERROR:" << std::endl;
231 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
232 <<
" environment variable to specify the location of the " << std::endl
233 <<
" image path where test images are located." << std::endl
246 std::cout <<
"Read image: " << filename << std::endl;
261 std::cout <<
"Write cropped image: " << filename << std::endl;
error that can be emitted by ViSP classes.
const std::string & getStringMessage() const
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)
unsigned int getWidth() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.