38 #include <visp3/io/vpImageIo.h>
39 #include <visp3/core/vpImageTools.h>
40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/io/vpParseArgv.h>
54 #define GETOPTARGS "cdi:o:h"
56 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
57 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
70 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
73 Read an image from the disk (Klimt.pgm and klimp.ppm), crop a rectangular area\n\
74 and check the resultings images.\n\
77 %s [-i <input image path>] [-o <output image path>] [-h]\n", name);
81 -i <input image path> %s\n\
82 Set image input path.\n\
83 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
85 Setting the VISP_INPUT_IMAGE_PATH environment\n\
86 variable produces the same behaviour than using\n\
89 -o <output image path> %s\n\
90 Set image output path.\n\
91 From this directory, creates the \"%s\"\n\
92 subdirectory depending on the username, where \n\
93 resulting images are written.\n\
97 ipath.c_str(), opath.c_str(), user.c_str());
100 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
115 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
122 case 'i': ipath = optarg_;
break;
123 case 'o': opath = optarg_;
break;
124 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
131 usage(argv[0], optarg_, ipath, opath, user);
return false;
break;
135 if ((c == 1) || (c == -1)) {
137 usage(argv[0], NULL, ipath, opath, user);
138 std::cerr <<
"ERROR: " << std::endl;
139 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
146 int main(
int argc,
const char ** argv)
149 std::string env_ipath;
150 std::string opt_ipath;
151 std::string opt_opath;
154 std::string username;
160 if (! env_ipath.empty())
165 opt_opath =
"C:/temp";
174 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
179 if (!opt_ipath.empty())
181 if (!opt_opath.empty())
194 usage(argv[0], NULL, ipath, opt_opath, username);
195 std::cerr << std::endl
196 <<
"ERROR:" << std::endl;
197 std::cerr <<
" Cannot create " << opath << std::endl;
198 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
205 if (opt_ipath.empty()) {
206 if (ipath != env_ipath) {
207 std::cout << std::endl
208 <<
"WARNING: " << std::endl;
209 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
210 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
211 <<
" we skip the environment variable." << std::endl;
216 if (opt_ipath.empty() && env_ipath.empty()){
217 usage(argv[0], NULL, ipath, opt_opath, username);
218 std::cerr << std::endl
219 <<
"ERROR:" << std::endl;
220 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
222 <<
" environment variable to specify the location of the " << std::endl
223 <<
" image path where test images are located." << std::endl << std::endl;
233 std::cout <<
"Read image: " << filename << std::endl;
235 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
237 std::vector< vpImage<unsigned char> > reference;
241 reference.push_back(crop);
243 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
247 reference.push_back(crop);
249 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
253 reference.push_back(crop);
255 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
258 vpRect roi(100, 100, 640, 640);
261 std::cout <<
" Cropped image saved in: " << filename << std::endl;
263 if (crop != reference[0]) {
264 std::cout <<
"Test 1 failed on uchar" << std::endl;
270 std::cout <<
" Cropped image saved in: " << filename << std::endl;
272 if (crop != reference[1]) {
273 std::cout <<
"Test 2 failed on uchar" << std::endl;
279 std::cout <<
" Cropped image saved in: " << filename << std::endl;
281 if (crop != reference[2]) {
282 std::cout <<
"Test 3 failed on uchar" << std::endl;
288 std::cout <<
" Cropped image saved in: " << filename << std::endl;
290 if (crop != reference[0]) {
291 std::cout <<
"Test 4 failed on uchar" << std::endl;
297 std::cout <<
" Cropped image saved in: " << filename << std::endl;
299 if (crop != reference[1]) {
300 std::cout <<
"Test 5 failed on uchar" << std::endl;
306 std::cout <<
" Cropped image saved in: " << filename << std::endl;
308 if (crop != reference[2]) {
309 std::cout <<
"Test 6 failed on uchar" << std::endl;
319 std::cout <<
"Read image: " << filename << std::endl;
321 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
325 std::vector< vpImage<vpRGBa> > reference;
328 reference.push_back(crop);
330 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
334 reference.push_back(crop);
336 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
340 reference.push_back(crop);
342 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
345 vpRect roi(100, 100, 640, 640);
348 std::cout <<
" Cropped image saved in: " << filename << std::endl;
350 if (crop != reference[0]) {
351 std::cout <<
"Test 1 failed on uchar" << std::endl;
357 std::cout <<
" Cropped image saved in: " << filename << std::endl;
359 if (crop != reference[1]) {
360 std::cout <<
"Test 2 failed on uchar" << std::endl;
366 std::cout <<
" Cropped image saved in: " << filename << std::endl;
368 if (crop != reference[2]) {
369 std::cout <<
"Test 3 failed on uchar" << std::endl;
375 std::cout <<
" Cropped image saved in: " << filename << std::endl;
377 if (crop != reference[0]) {
378 std::cout <<
"Test 4 failed on uchar" << std::endl;
384 std::cout <<
" Cropped image saved in: " << filename << std::endl;
386 if (crop != reference[1]) {
387 std::cout <<
"Test 5 failed on uchar" << std::endl;
393 std::cout <<
" Cropped image saved in: " << filename << std::endl;
395 if (crop != reference[2]) {
396 std::cout <<
"Test 6 failed on uchar" << std::endl;
401 std::cout <<
"Test succeed" << std::endl;
unsigned int getWidth() const
Type * bitmap
points toward the bitmap
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)
unsigned int getHeight() const
Defines a rectangle in the plane.
const std::string & getStringMessage(void) const
Send a reference (constant) related the error message (can be empty).