Visual Servoing Platform version 3.5.0
perfImageAddSub.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Test image addition / subtraction.
33 *
34 *****************************************************************************/
35
36#include <visp3/core/vpConfig.h>
37
44#if defined(VISP_HAVE_CATCH2)
45#define CATCH_CONFIG_ENABLE_BENCHMARKING
46#define CATCH_CONFIG_RUNNER
47#include <catch.hpp>
48#include <visp3/core/vpImageTools.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/io/vpImageIo.h>
51#include "common.hpp"
52
53TEST_CASE("Benchmark vpImageTools::imageAdd()", "[benchmark]") {
55 "Klimt/Klimt.pgm");
57 vpImageIo::read(I, filepath);
58
60 common_tools::fill(I2);
61
63 SECTION("Without saturation")
64 {
65 const bool saturation = false;
66
67 BENCHMARK("Benchmark naive imageAdd() code without saturation") {
68 common_tools::imageAddRef(I, I2, Iadd, saturation);
69 return I;
70 };
71
72 BENCHMARK("Benchmark ViSP imageAdd() code without saturation") {
73 vpImageTools::imageAdd(I, I2, Iadd, saturation);
74 return I;
75 };
76 }
77 SECTION("With saturation")
78 {
79 const bool saturation = true;
80
81 BENCHMARK("Benchmark naive imageAdd() code with saturation") {
82 common_tools::imageAddRef(I, I2, Iadd, saturation);
83 return I;
84 };
85
86 BENCHMARK("Benchmark ViSP imageAdd() code with saturation") {
87 vpImageTools::imageAdd(I, I2, Iadd, saturation);
88 return I;
89 };
90 }
91}
92
93TEST_CASE("Benchmark vpImageTools::imageSubtract()", "[benchmark]") {
95 "Klimt/Klimt.pgm");
97 vpImageIo::read(I, filepath);
98
100 common_tools::fill(I2);
101
103 SECTION("Without saturation")
104 {
105 const bool saturation = false;
106
107 BENCHMARK("Benchmark naive imageSub() code without saturation") {
108 common_tools::imageSubtractRef(I, I2, Isub, saturation);
109 return I;
110 };
111
112 BENCHMARK("Benchmark ViSP imageSub() code without saturation") {
113 vpImageTools::imageSubtract(I, I2, Isub, saturation);
114 return I;
115 };
116 }
117 SECTION("With saturation")
118 {
119 const bool saturation = true;
120
121 BENCHMARK("Benchmark naive imageSub() code with saturation") {
122 common_tools::imageSubtractRef(I, I2, Isub, saturation);
123 return I;
124 };
125
126 BENCHMARK("Benchmark ViSP imageSub() code with saturation") {
127 vpImageTools::imageSubtract(I, I2, Isub, saturation);
128 return I;
129 };
130 }
131}
132
133int main(int argc, char *argv[])
134{
135 Catch::Session session; // There must be exactly one instance
136
137 bool runBenchmark = false;
138 // Build a new parser on top of Catch's
139 using namespace Catch::clara;
140 auto cli = session.cli() // Get Catch's composite command line parser
141 | Opt(runBenchmark) // bind variable to a new option, with a hint string
142 ["--benchmark"] // the option names it will respond to
143 ("run benchmark?"); // description string for the help output
144
145 // Now pass the new composite back to Catch so it uses that
146 session.cli(cli);
147
148 // Let Catch (using Clara) parse the command line
149 session.applyCommandLine(argc, argv);
150
151 if (runBenchmark) {
152 int numFailed = session.run();
153
154 // numFailed is clamped to 255 as some unices only use the lower 8 bits.
155 // This clamping has already been applied, so just return it here
156 // You can also do any post run clean-up here
157 return numFailed;
158 }
159
160 return EXIT_SUCCESS;
161}
162#else
163int main()
164{
165 return 0;
166}
167#endif
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:149
static void imageSubtract(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Ires, bool saturate=false)
static void imageAdd(const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Ires, bool saturate=false)
unsigned int getWidth() const
Definition: vpImage.h:246
unsigned int getHeight() const
Definition: vpImage.h:188
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1365
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1670