39 #include <visp3/core/vpDebug.h> 40 #include <visp3/core/vpImage.h> 41 #include <visp3/core/vpImageTools.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/io/vpImageIo.h> 44 #include <visp3/io/vpParseArgv.h> 53 #define GETOPTARGS "cdi:o:n:h" 65 void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
66 const std::string &user,
int nbiter)
69 Test images addition / substraction.\n\ 72 %s [-i <input image path>] [-o <output image path>] [-n <nb iterations>]\n\ 78 -i <input image path> %s\n\ 79 Set image input path.\n\ 80 From this path read \"Klimt/Klimt.pgm\"\n\ 82 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 83 variable produces the same behaviour than using\n\ 86 -o <output image path> %s\n\ 87 Set image output path.\n\ 88 From this directory, creates the \"%s\"\n\ 89 subdirectory depending on the username, where \n\ 90 result output images are written.\n\ 92 -n <nb iterations> %d\n\ 93 Set the number of benchmark iterations.\n\ 96 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str(), nbiter);
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
113 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath,
const std::string &user,
128 nbiter = atoi(optarg_);
131 usage(argv[0], NULL, ipath, opath, user, nbiter);
140 usage(argv[0], optarg_, ipath, opath, user, nbiter);
146 if ((c == 1) || (c == -1)) {
148 usage(argv[0], NULL, ipath, opath, user, nbiter);
149 std::cerr <<
"ERROR: " << std::endl;
150 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
168 unsigned char *ptr_I1 = I1.
bitmap;
169 unsigned char *ptr_I2 = I2.
bitmap;
170 unsigned char *ptr_Ires = Ires.
bitmap;
172 for (
unsigned int cpt = 0; cpt < Ires.
getSize(); cpt++, ++ptr_I1, ++ptr_I2, ++ptr_Ires) {
173 *ptr_Ires = saturate ? vpMath::saturate<unsigned char>((
short int)*ptr_I1 + (
short int)*ptr_I2) : *ptr_I1 + *ptr_I2;
188 unsigned char *ptr_I1 = I1.
bitmap;
189 unsigned char *ptr_I2 = I2.
bitmap;
190 unsigned char *ptr_Ires = Ires.
bitmap;
192 for (
unsigned int cpt = 0; cpt < Ires.
getSize(); cpt++, ++ptr_I1, ++ptr_I2, ++ptr_Ires) {
193 *ptr_Ires = saturate ? vpMath::saturate<unsigned char>((
short int)*ptr_I1 - (
short int)*ptr_I2) : *ptr_I1 - *ptr_I2;
197 int main(
int argc,
const char **argv)
200 std::string env_ipath;
201 std::string opt_ipath;
202 std::string opt_opath;
205 std::string filename;
206 std::string username;
207 int nbIterations = 100;
214 if (!env_ipath.empty())
219 opt_opath =
"C:/temp";
228 if (getOptions(argc, argv, opt_ipath, opt_opath, username, nbIterations) ==
false) {
233 if (!opt_ipath.empty())
235 if (!opt_opath.empty())
247 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
248 std::cerr << std::endl <<
"ERROR:" << std::endl;
249 std::cerr <<
" Cannot create " << opath << std::endl;
250 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
257 if (opt_ipath.empty()) {
258 if (ipath != env_ipath) {
259 std::cout << std::endl <<
"WARNING: " << std::endl;
260 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 261 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
262 <<
" we skip the environment variable." << std::endl;
267 if (opt_ipath.empty() && env_ipath.empty()) {
268 usage(argv[0], NULL, ipath, opt_opath, username, nbIterations);
269 std::cerr << std::endl <<
"ERROR:" << std::endl;
270 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
271 <<
" environment variable to specify the location of the " << std::endl
272 <<
" image path where test images are located." << std::endl
284 std::cout <<
"Read image: " << filename << std::endl << std::endl;
294 std::cout <<
"(Iadd == I)? " << (Iadd == I) << std::endl;
303 std::cout <<
"In-place (Iadd == I)? " << (Iadd == I) << std::endl;
313 std::cout <<
"(Isub == I)? " << (Isub == I) << std::endl;
322 std::cout <<
"In-place (Isub == I)? " << (Isub == I) << std::endl;
327 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
328 I2.
bitmap[cpt] = (
unsigned char)cpt;
334 regularImageAdd(I, I2, Iadd_regular,
false);
335 if (Iadd != Iadd_regular) {
337 "false) (Iadd != Iadd_regular)!");
339 std::cout <<
"\nNo saturation (Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
344 regularImageAdd(I, I2, Iadd_regular,
true);
345 if (Iadd != Iadd_regular) {
347 "true) (Iadd != Iadd_regular)!");
349 std::cout <<
"Saturation (Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
356 regularImageSubtract(I, I2, Isub_regular,
false);
357 if (Isub != Isub_regular) {
359 "Isub, false) (Isub != Isub_regular)!");
361 std::cout <<
"\nNo saturation (Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
366 regularImageSubtract(I, I2, Isub_regular,
true);
367 if (Isub != Isub_regular) {
369 "Isub, true) (Isub != Isub_regular)!");
371 std::cout <<
"Saturation (Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
378 for (
int cpt = 0; cpt < nbIterations; cpt++) {
382 std::cout <<
"\nAdd no saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
386 for (
int cpt = 0; cpt < nbIterations; cpt++) {
387 regularImageAdd(I, Iadd_regular, Iadd_regular,
false);
390 std::cout <<
"Add regular no saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms" 391 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
392 std::cout <<
"(Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
396 std::cout <<
"\nWrite: " << filename << std::endl;
400 std::cout <<
"Write: " << filename << std::endl;
406 for (
int cpt = 0; cpt < nbIterations; cpt++) {
410 std::cout <<
"\nAdd saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
414 for (
int cpt = 0; cpt < nbIterations; cpt++) {
415 regularImageAdd(I, Iadd_regular, Iadd_regular,
true);
418 std::cout <<
"Add saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms" 419 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
420 std::cout <<
"(Iadd == Iadd_regular)? " << (Iadd == Iadd_regular) << std::endl;
424 std::cout <<
"\nWrite: " << filename << std::endl;
428 std::cout <<
"Write: " << filename << std::endl;
434 for (
int cpt = 0; cpt < nbIterations; cpt++) {
438 std::cout <<
"\nSubtract no saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
442 for (
int cpt = 0; cpt < nbIterations; cpt++) {
443 regularImageSubtract(I, Isub_regular, Isub_regular,
false);
446 std::cout <<
"Subtract regular no saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms" 447 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
448 std::cout <<
"(Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
452 std::cout <<
"\nWrite: " << filename << std::endl;
456 std::cout <<
"Write: " << filename << std::endl;
462 for (
int cpt = 0; cpt < nbIterations; cpt++) {
466 std::cout <<
"\nSubtract saturation ; t_sse (" << nbIterations <<
" iterations)=" << t_sse <<
" ms" << std::endl;
470 for (
int cpt = 0; cpt < nbIterations; cpt++) {
471 regularImageSubtract(I, Isub_regular, Isub_regular,
true);
474 std::cout <<
"Subtract saturation ; t (" << nbIterations <<
" iterations)=" << t <<
" ms" 475 <<
" ; Speed-up: " << (t / t_sse) <<
"X" << std::endl;
476 std::cout <<
"(Isub == Isub_regular)? " << (Isub == Isub_regular) << std::endl;
480 std::cout <<
"\nWrite: " << filename << std::endl;
484 std::cout <<
"Write: " << filename << std::endl;
489 vpRect r_crop(0, 0, 411, 507);
492 std::cout <<
"\nI_crop=" << I_crop.
getWidth() <<
"x" << I_crop.
getHeight() << std::endl;
498 regularImageSubtract(I_invert_regular, I_crop, I_invert_regular,
false);
499 std::cout <<
"(I_invert == I_invert_regular)? " << (I_invert == I_invert_regular) << std::endl;
504 std::cout <<
"(I_invert2 == I_white)? " << (I_invert2 == I_white) << std::endl;
507 std::cout <<
"Write: " << filename << std::endl;
513 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.