42 #include <visp/vpImage.h>
43 #include <visp/vpImageIo.h>
44 #include <visp/vpImageTools.h>
45 #include <visp/vpIoTools.h>
46 #include <visp/vpRect.h>
47 #include <visp/vpParseArgv.h>
48 #include <visp/vpDebug.h>
63 #define GETOPTARGS "i:o:h"
65 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
66 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
79 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
82 Read an image from the disk (Klimt.pgm), crop a rectangular area\n\
83 and save the cropped image on the disk (Klimt_cropped.pgm).\n\
86 %s [-i <input image path>] [-o <output image path>]\n\
92 -i <input image path> %s\n\
93 Set image input path.\n\
94 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
100 -o <output image path> %s\n\
101 Set image output path.\n\
102 From this directory, creates the \"%s\"\n\
103 subdirectory depending on the username, where \n\
104 Klimt_cropped.pgm output image is written.\n\
107 Print the help.\n\n",
108 ipath.c_str(), opath.c_str(), user.c_str());
111 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
126 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
133 case 'i': ipath = optarg_;
break;
134 case 'o': opath = optarg_;
break;
135 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
138 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
142 if ((c == 1) || (c == -1)) {
144 usage(argv[0], NULL, ipath, opath, user);
145 std::cerr <<
"ERROR: " << std::endl;
146 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
154 main(
int argc,
const char ** argv)
157 std::string env_ipath;
158 std::string opt_ipath;
159 std::string opt_opath;
162 std::string filename;
163 std::string username;
166 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
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())
205 usage(argv[0], NULL, ipath, opt_opath, username);
206 std::cerr << std::endl
207 <<
"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()) {
217 if (ipath != env_ipath) {
218 std::cout << std::endl
219 <<
"WARNING: " << std::endl;
220 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
221 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
222 <<
" we skip the environment variable." << std::endl;
227 if (opt_ipath.empty() && env_ipath.empty()){
228 usage(argv[0], NULL, ipath, opt_opath, username);
229 std::cerr << std::endl
230 <<
"ERROR:" << std::endl;
231 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
233 <<
" environment variable to specify the location of the " << std::endl
234 <<
" image path where test images are located." << std::endl << 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 << std::endl;
static void write(const vpImage< unsigned char > &I, const char *filename)
unsigned int getWidth() const
error that can be emited by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.
static void read(vpImage< unsigned char > &I, const char *filename)