44 #include <visp/vpImage.h>
45 #include <visp/vpRGBa.h>
46 #include <visp/vpImageIo.h>
47 #include <visp/vpImageTools.h>
48 #include <visp/vpIoTools.h>
49 #include <visp/vpParseArgv.h>
50 #include <visp/vpDebug.h>
51 #include <visp/vpTime.h>
64 #define GETOPTARGS "i:o:h"
69 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
83 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
86 Read an image from the disk, undistort it \n\
87 and save the undistorted image on the disk.\n\
88 (Klimt_undistorted.pgm).\n\
91 %s [-i <input image path>] [-o <output image path>]\n\
97 -i <input image path> %s\n\
98 Set image input path.\n\
99 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
101 Setting the VISP_INPUT_IMAGE_PATH environment\n\
102 variable produces the same behaviour than using\n\
105 -o <output image path> %s\n\
106 Set image output path.\n\
107 From this directory, creates the \"%s\"\n\
108 subdirectory depending on the username, where \n\
109 Klimt_undistorted.pgm output image is written.\n\
112 Print the help.\n\n",
113 ipath.c_str(), opath.c_str(), user.c_str());
116 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
131 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
138 case 'i': ipath = optarg_;
break;
139 case 'o': opath = optarg_;
break;
140 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
143 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, ipath, opath, user);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
158 int main(
int argc,
const char ** argv)
161 std::string env_ipath;
162 std::string opt_ipath;
163 std::string opt_opath;
166 std::string filename;
167 std::string username;
173 if (! env_ipath.empty())
177 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
179 #elif defined(_WIN32)
180 opt_opath =
"C:\\temp";
187 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
192 if (!opt_ipath.empty())
194 if (!opt_opath.empty())
207 usage(argv[0], NULL, ipath, opt_opath, username);
208 std::cerr << std::endl
209 <<
"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
221 <<
"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
232 <<
"ERROR:" << std::endl;
233 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
235 <<
" environment variable to specify the location of the " << std::endl
236 <<
" image path where test images are located." << std::endl << std::endl;
258 std::cout <<
"Read image: " << filename << std::endl;
261 std::cout <<
"Undistortion in process... " << std::endl;
268 for(
unsigned int i=0;i<100;i++)
274 std::cout<<
"Time for 100 undistortion (ms): "<< endtime - begintime
283 std::cout <<
"Write undistorted image: " << filename << std::endl;
288 std::cout <<
"Catch an exception: " << e << std::endl;
static void write(const vpImage< unsigned char > &I, const char *filename)
error that can be emited by ViSP classes.
static double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Generic class defining intrinsic camera parameters.
static void read(vpImage< unsigned char > &I, const char *filename)
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)