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"
80 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
83 Read an image from the disk, undistort it \n\
84 and save the undistorted image on the disk.\n\
85 (Klimt_undistorted.pgm).\n\
88 %s [-i <input image path>] [-o <output image path>]\n\
94 -i <input image path> %s\n\
95 Set image input path.\n\
96 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
98 Setting the VISP_INPUT_IMAGE_PATH environment\n\
99 variable produces the same behaviour than using\n\
102 -o <output image path> %s\n\
103 Set image output path.\n\
104 From this directory, creates the \"%s\"\n\
105 subdirectory depending on the username, where \n\
106 Klimt_undistorted.pgm output image is written.\n\
109 Print the help.\n\n",
110 ipath.c_str(), opath.c_str(), user.c_str());
113 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
128 bool getOptions(
int argc,
const char **argv,
129 std::string &ipath, std::string &opath, std::string user)
136 case 'i': ipath = optarg;
break;
137 case 'o': opath = optarg;
break;
138 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
141 usage(argv[0], optarg, ipath, opath, user);
return false;
break;
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL, ipath, opath, user);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
156 int main(
int argc,
const char ** argv)
158 std::string env_ipath;
159 std::string opt_ipath;
160 std::string opt_opath;
163 std::string filename;
164 std::string username;
167 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
172 if (! env_ipath.empty())
179 opt_opath =
"C:\\temp";
186 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
191 if (!opt_ipath.empty())
193 if (!opt_opath.empty())
206 usage(argv[0], NULL, ipath, opt_opath, username);
207 std::cerr << std::endl
208 <<
"ERROR:" << std::endl;
209 std::cerr <<
" Cannot create " << opath << std::endl;
210 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
217 if (opt_ipath.empty()) {
218 if (ipath != env_ipath) {
219 std::cout << std::endl
220 <<
"WARNING: " << std::endl;
221 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
222 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
223 <<
" we skip the environment variable." << std::endl;
228 if (opt_ipath.empty() && env_ipath.empty()){
229 usage(argv[0], NULL, ipath, opt_opath, username);
230 std::cerr << std::endl
231 <<
"ERROR:" << std::endl;
232 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
234 <<
" environment variable to specify the location of the " << std::endl
235 <<
" image path where test images are located." << std::endl << std::endl;
257 std::cout <<
"Read image: " << filename << std::endl;
260 std::cout <<
"Undistortion in process... " << std::endl;
267 for(
unsigned int i=0;i<100;i++)
273 std::cout<<
"Time for 100 undistortion (ms): "<< endtime - begintime
282 std::cout <<
"Write undistorted image: " << filename << std::endl;