40 #include <visp3/core/vpImage.h> 41 #include <visp3/core/vpRGBa.h> 42 #include <visp3/io/vpImageIo.h> 43 #include <visp3/core/vpImageTools.h> 44 #include <visp3/core/vpIoTools.h> 45 #include <visp3/io/vpParseArgv.h> 46 #include <visp3/core/vpDebug.h> 47 #include <visp3/core/vpTime.h> 60 #define GETOPTARGS "cdi: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, undistort it \n\ 83 and save the undistorted image on the disk.\n\ 84 (Klimt_undistorted.pgm).\n\ 87 %s [-i <input image path>] [-o <output image path>]\n\ 93 -i <input image path> %s\n\ 94 Set image input path.\n\ 95 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\ 97 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 98 variable produces the same behaviour than using\n\ 101 -o <output image path> %s\n\ 102 Set image output path.\n\ 103 From this directory, creates the \"%s\"\n\ 104 subdirectory depending on the username, where \n\ 105 Klimt_undistorted.pgm output image is written.\n\ 108 Print the help.\n\n",
109 ipath.c_str(), opath.c_str(), user.c_str());
112 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
127 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
134 case 'i': ipath = optarg_;
break;
135 case 'o': opath = optarg_;
break;
136 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 bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Generic class defining intrinsic camera parameters.
VISP_EXPORT double measureTimeMs()
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)