Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
perfImageAddSub.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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 "common.hpp"
48#include <catch.hpp>
49#include <visp3/core/vpImageTools.h>
50#include <visp3/core/vpIoTools.h>
51#include <visp3/io/vpImageIo.h>
52
53TEST_CASE("Benchmark vpImageTools::imageAdd()", "[benchmark]")
54{
55 const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "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 {
69 common_tools::imageAddRef(I, I2, Iadd, saturation);
70 return I;
71 };
72
73 BENCHMARK("Benchmark ViSP imageAdd() code without saturation")
74 {
75 vpImageTools::imageAdd(I, I2, Iadd, saturation);
76 return I;
77 };
78 }
79 SECTION("With saturation")
80 {
81 const bool saturation = true;
82
83 BENCHMARK("Benchmark naive imageAdd() code with saturation")
84 {
85 common_tools::imageAddRef(I, I2, Iadd, saturation);
86 return I;
87 };
88
89 BENCHMARK("Benchmark ViSP imageAdd() code with saturation")
90 {
91 vpImageTools::imageAdd(I, I2, Iadd, saturation);
92 return I;
93 };
94 }
95}
96
97TEST_CASE("Benchmark vpImageTools::imageSubtract()", "[benchmark]")
98{
99 const std::string filepath = vpIoTools::createFilePath(vpIoTools::getViSPImagesDataPath(), "Klimt/Klimt.pgm");
101 vpImageIo::read(I, filepath);
102
104 common_tools::fill(I2);
105
107 SECTION("Without saturation")
108 {
109 const bool saturation = false;
110
111 BENCHMARK("Benchmark naive imageSub() code without saturation")
112 {
113 common_tools::imageSubtractRef(I, I2, Isub, saturation);
114 return I;
115 };
116
117 BENCHMARK("Benchmark ViSP imageSub() code without saturation")
118 {
119 vpImageTools::imageSubtract(I, I2, Isub, saturation);
120 return I;
121 };
122 }
123 SECTION("With saturation")
124 {
125 const bool saturation = true;
126
127 BENCHMARK("Benchmark naive imageSub() code with saturation")
128 {
129 common_tools::imageSubtractRef(I, I2, Isub, saturation);
130 return I;
131 };
132
133 BENCHMARK("Benchmark ViSP imageSub() code with saturation")
134 {
135 vpImageTools::imageSubtract(I, I2, Isub, saturation);
136 return I;
137 };
138 }
139}
140
141int main(int argc, char *argv[])
142{
143 Catch::Session session; // There must be exactly one instance
144
145 bool runBenchmark = false;
146 // Build a new parser on top of Catch's
147 using namespace Catch::clara;
148 auto cli = session.cli() // Get Catch's composite command line parser
149 | Opt(runBenchmark) // bind variable to a new option, with a hint string
150 ["--benchmark"] // the option names it will respond to
151 ("run benchmark?"); // description string for the help output
152
153 // Now pass the new composite back to Catch so it uses that
154 session.cli(cli);
155
156 // Let Catch (using Clara) parse the command line
157 session.applyCommandLine(argc, argv);
158
159 if (runBenchmark) {
160 int numFailed = session.run();
161
162 // numFailed is clamped to 255 as some unices only use the lower 8 bits.
163 // This clamping has already been applied, so just return it here
164 // You can also do any post run clean-up here
165 return numFailed;
166 }
167
168 return EXIT_SUCCESS;
169}
170#else
171int main() { return EXIT_SUCCESS; }
172#endif
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
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)
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static std::string getViSPImagesDataPath()
static std::string createFilePath(const std::string &parent, const std::string &child)