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"
72 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
73 const std::string &user)
76 Read an image from the disk (Klimt.pgm), crop a rectangular area\n\
77 and 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);
121 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
135 usage(argv[0],
nullptr, ipath, opath, user);
144 usage(argv[0], optarg_, ipath, opath, user);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0],
nullptr, ipath, opath, user);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
161 int main(
int argc,
const char **argv)
164 std::string env_ipath;
165 std::string opt_ipath;
166 std::string opt_opath;
169 std::string filename;
170 std::string username;
177 if (!env_ipath.empty())
182 opt_opath =
"C:/temp";
191 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
196 if (!opt_ipath.empty())
198 if (!opt_opath.empty())
211 usage(argv[0],
nullptr, ipath, opt_opath, username);
212 std::cerr << std::endl <<
"ERROR:" << std::endl;
213 std::cerr <<
" Cannot create " << opath << std::endl;
214 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
221 if (opt_ipath.empty()) {
222 if (ipath != env_ipath) {
223 std::cout << std::endl <<
"WARNING: " << std::endl;
224 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
225 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
226 <<
" we skip the environment variable." << std::endl;
231 if (opt_ipath.empty() && env_ipath.empty()) {
232 usage(argv[0],
nullptr, ipath, opt_opath, username);
233 std::cerr << std::endl <<
"ERROR:" << std::endl;
234 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
235 <<
" environment variable to specify the location of the " << std::endl
236 <<
" image path where test images are located." << std::endl
249 std::cout <<
"Read image: " << filename << std::endl;
264 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.