40 #include <visp3/core/vpDebug.h> 41 #include <visp3/core/vpImage.h> 42 #include <visp3/core/vpImageTools.h> 43 #include <visp3/core/vpIoTools.h> 44 #include <visp3/core/vpRGBa.h> 45 #include <visp3/core/vpTime.h> 46 #include <visp3/io/vpImageIo.h> 47 #include <visp3/io/vpParseArgv.h> 59 #define GETOPTARGS "cdi:o:h" 75 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
76 const std::string &user)
79 Read an image from the disk, undistort it \n\ 80 and save the undistorted image on the disk.\n\ 81 (Klimt_undistorted.pgm).\n\ 84 %s [-i <input image path>] [-o <output image path>]\n\ 90 -i <input image path> %s\n\ 91 Set image input path.\n\ 92 From this path read \"Klimt/Klimt.pgm\"\n\ 94 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 95 variable produces the same behaviour than using\n\ 98 -o <output image path> %s\n\ 99 Set image output path.\n\ 100 From this directory, creates the \"%s\"\n\ 101 subdirectory depending on the username, where \n\ 102 Klimt_undistorted.pgm output image is written.\n\ 105 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
123 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
137 usage(argv[0], NULL, ipath, opath, user);
146 usage(argv[0], optarg_, ipath, opath, user);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0], NULL, ipath, opath, user);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
163 int main(
int argc,
const char **argv)
166 std::string env_ipath;
167 std::string opt_ipath;
168 std::string opt_opath;
171 std::string filename;
172 std::string username;
179 if (!env_ipath.empty())
183 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 185 #elif defined(_WIN32) 186 opt_opath =
"C:\\temp";
193 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
198 if (!opt_ipath.empty())
200 if (!opt_opath.empty())
212 usage(argv[0], NULL, ipath, opt_opath, username);
213 std::cerr << std::endl <<
"ERROR:" << std::endl;
214 std::cerr <<
" Cannot create " << opath << std::endl;
215 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
222 if (opt_ipath.empty()) {
223 if (ipath != env_ipath) {
224 std::cout << std::endl <<
"WARNING: " << std::endl;
225 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 226 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
227 <<
" we skip the environment variable." << std::endl;
232 if (opt_ipath.empty() && env_ipath.empty()) {
233 usage(argv[0], NULL, ipath, opt_opath, username);
234 std::cerr << std::endl <<
"ERROR:" << std::endl;
235 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
236 <<
" environment variable to specify the location of the " << std::endl
237 <<
" image path where test images are located." << std::endl
260 std::cout <<
"Read image: " << filename << std::endl;
263 std::cout <<
"Undistortion in process... " << std::endl;
270 for (
unsigned int i = 0; i < 100; i++)
276 std::cout <<
"Time for 100 undistortion (ms): " << endtime - begintime << std::endl;
284 std::cout <<
"Write undistorted image: " << filename << std::endl;
288 std::cout <<
"Catch an exception: " << e << std::endl;
error that can be emited by ViSP classes.
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Generic class defining intrinsic camera parameters.
static void read(vpImage< unsigned char > &I, const std::string &filename)
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)