38 #include <visp3/core/vpImage.h>
39 #include <visp3/io/vpImageIo.h>
40 #include <visp3/core/vpImageTools.h>
41 #include <visp3/core/vpIoTools.h>
42 #include <visp3/io/vpParseArgv.h>
43 #include <visp3/core/vpDebug.h>
52 #define GETOPTARGS "cdi:o:n:h"
54 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user,
int nbiter);
55 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user,
int &nbiter);
67 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user,
int nbiter)
70 Test images addition / substraction.\n\
73 %s [-i <input image path>] [-o <output image path>] [-n <nb iterations>]\n\
79 -i <input image path> %s\n\
80 Set image input path.\n\
81 From this path read \"ViSP-images/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 result output images are written.\n\
93 -n <nb iterations> %d\n\
94 Set the number of benchmark iterations.\n\
98 ipath.c_str(), opath.c_str(), user.c_str(), nbiter);
101 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,
int &nbiter)
122 case 'i': ipath = optarg_;
break;
123 case 'o': opath = optarg_;
break;
124 case 'n': nbiter = atoi(optarg_);
break;
125 case 'h': usage(argv[0], NULL, ipath, opath, user, nbiter);
return false;
break;
132 usage(argv[0], optarg_, ipath, opath, user, nbiter);
return false;
break;
136 if ((c == 1) || (c == -1)) {
138 usage(argv[0], NULL, ipath, opath, user, nbiter);
139 std::cerr <<
"ERROR: " << std::endl;
140 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
157 unsigned char *ptr_I1 = I1.
bitmap;
158 unsigned char *ptr_I2 = I2.
bitmap;
159 unsigned char *ptr_Ires = Ires.
bitmap;
161 for (
unsigned int cpt = 0; cpt < Ires.
getSize(); cpt++, ++ptr_I1, ++ptr_I2, ++ptr_Ires) {
162 *ptr_Ires = saturate ? vpMath::saturate<unsigned char>( (
short int) *ptr_I1 + (
short int) *ptr_I2 ) : *ptr_I1 + *ptr_I2;
176 unsigned char *ptr_I1 = I1.
bitmap;
177 unsigned char *ptr_I2 = I2.
bitmap;
178 unsigned char *ptr_Ires = Ires.
bitmap;
180 for (
unsigned int cpt = 0; cpt < Ires.
getSize(); cpt++, ++ptr_I1, ++ptr_I2, ++ptr_Ires) {
181 *ptr_Ires = saturate ? vpMath::saturate<unsigned char>( (
short int) *ptr_I1 - (
short int) *ptr_I2 ) : *ptr_I1 - *ptr_I2;
186 main(
int argc,
const char ** argv)
189 std::string env_ipath;
190 std::string opt_ipath;
191 std::string opt_opath;
194 std::string filename;
195 std::string username;
196 int nbIterations = 100;
202 if (! env_ipath.empty())
207 opt_opath =
"C:/temp";
216 if (getOptions(argc, argv, opt_ipath, opt_opath, username, nbIterations) ==
false) {
221 if (!opt_ipath.empty())
223 if (!opt_opath.empty())
236 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
237 std::cerr << std::endl
238 <<
"ERROR:" << std::endl;
239 std::cerr <<
" Cannot create " << opath << std::endl;
240 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
247 if (opt_ipath.empty()) {
248 if (ipath != env_ipath) {
249 std::cout << std::endl
250 <<
"WARNING: " << std::endl;
251 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
252 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
253 <<
" we skip the environment variable." << std::endl;
258 if (opt_ipath.empty() && env_ipath.empty()){
259 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
260 std::cerr << std::endl
261 <<
"ERROR:" << std::endl;
262 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
264 <<
" environment variable to specify the location of the " << std::endl
265 <<
" image path where test images are located." << std::endl << std::endl;
276 std::cout <<
"Read image: " << filename << std::endl << std::endl;
287 std::cout <<
"(Iadd == I)? " << (Iadd == I) << std::endl;
296 std::cout <<
"In-place (Iadd == I)? " << (Iadd == I) << std::endl;
307 std::cout <<
"(Isub == I)? " << (Isub == I) << std::endl;
316 std::cout <<
"In-place (Isub == I)? " << (Isub == I) << std::endl;
322 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
323 I2.
bitmap[cpt] = (
unsigned char) cpt;
329 regularImageAdd(I, I2, Iadd_regular,
false);
330 if (Iadd != Iadd_regular) {
333 std::cout <<
"\nNo saturation (Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
338 regularImageAdd(I, I2, Iadd_regular,
true);
339 if (Iadd != Iadd_regular) {
342 std::cout <<
"Saturation (Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
350 regularImageSubtract(I, I2, Isub_regular,
false);
351 if (Isub != Isub_regular) {
354 std::cout <<
"\nNo saturation (Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
359 regularImageSubtract(I, I2, Isub_regular,
true);
360 if (Isub != Isub_regular) {
363 std::cout <<
"Saturation (Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
371 for (
int cpt = 0; cpt < nbIterations; cpt++) {
375 std::cout <<
"\nAdd no saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
379 for (
int cpt = 0; cpt < nbIterations; cpt++) {
380 regularImageAdd(I, Iadd_regular, Iadd_regular,
false);
383 std::cout <<
"Add regular no saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms"
384 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
385 std::cout <<
"(Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
389 std::cout <<
"\nWrite: " << filename << std::endl;
393 std::cout <<
"Write: " << filename << std::endl;
400 for (
int cpt = 0; cpt < nbIterations; cpt++) {
404 std::cout <<
"\nAdd saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
408 for (
int cpt = 0; cpt < nbIterations; cpt++) {
409 regularImageAdd(I, Iadd_regular, Iadd_regular,
true);
412 std::cout <<
"Add saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms"
413 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
414 std::cout <<
"(Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
418 std::cout <<
"\nWrite: " << filename << std::endl;
422 std::cout <<
"Write: " << filename << std::endl;
429 for (
int cpt = 0; cpt < nbIterations; cpt++) {
433 std::cout <<
"\nSubtract no saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
437 for (
int cpt = 0; cpt < nbIterations; cpt++) {
438 regularImageSubtract(I, Isub_regular, Isub_regular,
false);
441 std::cout <<
"Subtract regular no saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms"
442 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
443 std::cout <<
"(Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
447 std::cout <<
"\nWrite: " << filename << std::endl;
451 std::cout <<
"Write: " << filename << std::endl;
458 for (
int cpt = 0; cpt < nbIterations; cpt++) {
462 std::cout <<
"\nSubtract saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
466 for (
int cpt = 0; cpt < nbIterations; cpt++) {
467 regularImageSubtract(I, Isub_regular, Isub_regular,
true);
470 std::cout <<
"Subtract saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms"
471 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
472 std::cout <<
"(Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
476 std::cout <<
"\nWrite: " << filename << std::endl;
480 std::cout <<
"Write: " << filename << std::endl;
486 vpRect r_crop(0, 0, 411, 507);
489 std::cout <<
"\nI_crop=" << I_crop.
getWidth() <<
"x" << I_crop.
getHeight() << std::endl;
495 regularImageSubtract(I_invert_regular, I_crop, I_invert_regular,
false);
496 std::cout <<
"(I_invert == I_invert_regular)? " << (I_invert == I_invert_regular) << std::endl;
501 std::cout <<
"(I_invert2 == I_white)? " << (I_invert2 == I_white) << std::endl;
504 std::cout <<
"Write: " << filename << std::endl;
511 std::cerr <<
"Catch an exception: " << e << std::endl;
unsigned int getWidth() const
Type * bitmap
points toward the bitmap
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)
unsigned int getSize() const
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const
Defines a rectangle in the plane.