38 #include <visp3/core/vpImage.h>
39 #include <visp3/io/vpImageIo.h>
40 #include <visp3/core/vpImageTools.h>
41 #include <visp3/core/vpIoTools.h>
42 #include <visp3/core/vpRect.h>
43 #include <visp3/io/vpParseArgv.h>
44 #include <visp3/core/vpDebug.h>
59 #define GETOPTARGS "cdi:o:h"
61 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
62 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
75 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
78 Read an image from the disk (Klimt.pgm), crop a rectangular area\n\
79 and save the cropped image on the disk (Klimt_cropped.pgm).\n\
82 %s [-i <input image path>] [-o <output image path>]\n\
88 -i <input image path> %s\n\
89 Set image input path.\n\
90 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
92 Setting the VISP_INPUT_IMAGE_PATH environment\n\
93 variable produces the same behaviour than using\n\
96 -o <output image path> %s\n\
97 Set image output path.\n\
98 From this directory, creates the \"%s\"\n\
99 subdirectory depending on the username, where \n\
100 Klimt_cropped.pgm output image is written.\n\
103 Print the help.\n\n",
104 ipath.c_str(), opath.c_str(), user.c_str());
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
122 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
129 case 'i': ipath = optarg_;
break;
130 case 'o': opath = optarg_;
break;
131 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;
169 if (! env_ipath.empty())
174 opt_opath =
"C:/temp";
183 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
188 if (!opt_ipath.empty())
190 if (!opt_opath.empty())
203 usage(argv[0], NULL, ipath, opt_opath, username);
204 std::cerr << std::endl
205 <<
"ERROR:" << std::endl;
206 std::cerr <<
" Cannot create " << opath << std::endl;
207 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
214 if (opt_ipath.empty()) {
215 if (ipath != env_ipath) {
216 std::cout << std::endl
217 <<
"WARNING: " << std::endl;
218 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
219 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
220 <<
" we skip the environment variable." << std::endl;
225 if (opt_ipath.empty() && env_ipath.empty()){
226 usage(argv[0], NULL, ipath, opt_opath, username);
227 std::cerr << std::endl
228 <<
"ERROR:" << std::endl;
229 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
231 <<
" environment variable to specify the location of the " << std::endl
232 <<
" image path where test images are located." << std::endl << std::endl;
244 std::cout <<
"Read image: " << filename << std::endl;
259 std::cout <<
"Write cropped image: " << filename << std::endl;
unsigned int getWidth() const
error that can be emited by ViSP classes.
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)
Defines a rectangle in the plane.
const std::string & getStringMessage(void) const
Send a reference (constant) related the error message (can be empty).