39 #include <visp3/core/vpImageTools.h> 40 #include <visp3/core/vpIoTools.h> 41 #include <visp3/io/vpImageIo.h> 42 #include <visp3/io/vpParseArgv.h> 54 #define GETOPTARGS "cdi:o:h" 67 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
68 const std::string &user)
71 Read an image from the disk (Klimt.pgm and klimp.ppm), crop a rectangular area\n\ 72 and check the resultings images.\n\ 75 %s [-i <input image path>] [-o <output image path>] [-h]\n", name);
79 -i <input image path> %s\n\ 80 Set image input path.\n\ 81 From this path read \"Klimt/Klimt.pgm\"\n\ 83 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 84 variable produces the same behaviour than using\n\ 87 -o <output image path> %s\n\ 88 Set image output path.\n\ 89 From this directory, creates the \"%s\"\n\ 90 subdirectory depending on the username, where \n\ 91 resulting images are written.\n\ 94 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
97 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
112 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user)
126 usage(argv[0], NULL, ipath, opath, user);
135 usage(argv[0], optarg_, ipath, opath, user);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0], NULL, ipath, opath, user);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
152 int main(
int argc,
const char **argv)
155 std::string env_ipath;
156 std::string opt_ipath;
157 std::string opt_opath;
160 std::string username;
167 if (!env_ipath.empty())
172 opt_opath =
"C:/temp";
181 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
186 if (!opt_ipath.empty())
188 if (!opt_opath.empty())
200 usage(argv[0], NULL, ipath, opt_opath, username);
201 std::cerr << std::endl <<
"ERROR:" << std::endl;
202 std::cerr <<
" Cannot create " << opath << std::endl;
203 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
210 if (opt_ipath.empty()) {
211 if (ipath != env_ipath) {
212 std::cout << std::endl <<
"WARNING: " << std::endl;
213 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 214 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
215 <<
" we skip the environment variable." << std::endl;
220 if (opt_ipath.empty() && env_ipath.empty()) {
221 usage(argv[0], NULL, ipath, opt_opath, username);
222 std::cerr << std::endl <<
"ERROR:" << std::endl;
223 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
224 <<
" environment variable to specify the location of the " << std::endl
225 <<
" image path where test images are located." << std::endl
235 std::cout <<
"Read image: " << filename << std::endl;
237 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
239 std::vector<vpImage<unsigned char> > reference;
243 reference.push_back(crop);
245 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
249 reference.push_back(crop);
251 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
255 reference.push_back(crop);
257 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
260 vpRect roi(100, 100, 640, 640);
263 std::cout <<
" Cropped image saved in: " << filename << std::endl;
265 if (crop != reference[0]) {
266 std::cout <<
"Test 1 failed on uchar" << std::endl;
272 std::cout <<
" Cropped image saved in: " << filename << std::endl;
274 if (crop != reference[1]) {
275 std::cout <<
"Test 2 failed on uchar" << std::endl;
281 std::cout <<
" Cropped image saved in: " << filename << std::endl;
283 if (crop != reference[2]) {
284 std::cout <<
"Test 3 failed on uchar" << std::endl;
290 std::cout <<
" Cropped image saved in: " << filename << std::endl;
292 if (crop != reference[0]) {
293 std::cout <<
"Test 4 failed on uchar" << std::endl;
299 std::cout <<
" Cropped image saved in: " << filename << std::endl;
301 if (crop != reference[1]) {
302 std::cout <<
"Test 5 failed on uchar" << std::endl;
308 std::cout <<
" Cropped image saved in: " << filename << std::endl;
310 if (crop != reference[2]) {
311 std::cout <<
"Test 6 failed on uchar" << std::endl;
321 std::cout <<
"Read image: " << filename << std::endl;
323 std::cout <<
"Image size: " << I.
getWidth() <<
" " << I.
getHeight() << std::endl;
327 std::vector<vpImage<vpRGBa> > reference;
330 reference.push_back(crop);
332 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
336 reference.push_back(crop);
338 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
342 reference.push_back(crop);
344 std::cout <<
" Cropped image reference saved in: " << filename << std::endl;
347 vpRect roi(100, 100, 640, 640);
350 std::cout <<
" Cropped image saved in: " << filename << std::endl;
352 if (crop != reference[0]) {
353 std::cout <<
"Test 1 failed on uchar" << std::endl;
359 std::cout <<
" Cropped image saved in: " << filename << std::endl;
361 if (crop != reference[1]) {
362 std::cout <<
"Test 2 failed on uchar" << std::endl;
368 std::cout <<
" Cropped image saved in: " << filename << std::endl;
370 if (crop != reference[2]) {
371 std::cout <<
"Test 3 failed on uchar" << std::endl;
377 std::cout <<
" Cropped image saved in: " << filename << std::endl;
379 if (crop != reference[0]) {
380 std::cout <<
"Test 4 failed on uchar" << std::endl;
386 std::cout <<
" Cropped image saved in: " << filename << std::endl;
388 if (crop != reference[1]) {
389 std::cout <<
"Test 5 failed on uchar" << std::endl;
395 std::cout <<
" Cropped image saved in: " << filename << std::endl;
397 if (crop != reference[2]) {
398 std::cout <<
"Test 6 failed on uchar" << std::endl;
403 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).