39 #include <visp3/core/vpDebug.h> 40 #include <visp3/core/vpImage.h> 41 #include <visp3/core/vpImageTools.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/core/vpRect.h> 44 #include <visp3/io/vpImageIo.h> 45 #include <visp3/io/vpParseArgv.h> 60 #define GETOPTARGS "cdi:o:h" 73 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
74 const std::string &user)
77 Read an image from the disk (Klimt.pgm), crop a rectangular area\n\ 78 and save the cropped image on the disk (Klimt_cropped.pgm).\n\ 81 %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", ipath.c_str(), opath.c_str(), user.c_str());
105 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
120 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
134 usage(argv[0], NULL, ipath, opath, user);
143 usage(argv[0], optarg_, ipath, opath, user);
149 if ((c == 1) || (c == -1)) {
151 usage(argv[0], NULL, ipath, opath, user);
152 std::cerr <<
"ERROR: " << std::endl;
153 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
160 int main(
int argc,
const char **argv)
163 std::string env_ipath;
164 std::string opt_ipath;
165 std::string opt_opath;
168 std::string filename;
169 std::string username;
176 if (!env_ipath.empty())
181 opt_opath =
"C:/temp";
190 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
195 if (!opt_ipath.empty())
197 if (!opt_opath.empty())
209 usage(argv[0], NULL, 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], NULL, 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;
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).