Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
perfGaussianFilter.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 * Benchmark Gaussian filter.
33 *
34*****************************************************************************/
35
36#include <visp3/core/vpConfig.h>
37
38#ifdef VISP_HAVE_CATCH2
39#define CATCH_CONFIG_ENABLE_BENCHMARKING
40#define CATCH_CONFIG_RUNNER
41#include <catch.hpp>
42
43#include <visp3/core/vpGaussianFilter.h>
44#include <visp3/core/vpImageFilter.h>
45#include <visp3/core/vpIoTools.h>
46#include <visp3/io/vpImageIo.h>
47
48static const std::string ipath = vpIoTools::getViSPImagesDataPath();
49static std::string imagePath = vpIoTools::createFilePath(ipath, "faces/1280px-Solvay_conference_1927.png");
50
51TEST_CASE("vpGaussianFilter", "[benchmark]")
52{
53 SECTION("unsigned char")
54 {
55 vpImage<unsigned char> I, I_blur;
56 vpImageIo::read(I, imagePath);
57
58 const float sigma = 5.0f;
59 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma);
60 BENCHMARK("Benchmark vpGaussianFilter uchar")
61 {
62 gaussianFilter.apply(I, I_blur);
63 return I_blur;
64 };
65 }
66
67 SECTION("vpRGBa")
68 {
69 vpImage<vpRGBa> I, I_blur;
70 vpImageIo::read(I, imagePath);
71
72 const float sigma = 5.0f;
73 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma);
74 BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
75 {
76 gaussianFilter.apply(I, I_blur);
77 return I_blur;
78 };
79 }
80
81 SECTION("vpRGBa + deinterleave")
82 {
83 vpImage<vpRGBa> I, I_blur;
84 vpImageIo::read(I, imagePath);
85
86 const float sigma = 5.0f;
87 const bool deinterleave = true;
88 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma, deinterleave);
89 BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
90 {
91 gaussianFilter.apply(I, I_blur);
92 return I_blur;
93 };
94 }
95}
96
97TEST_CASE("vpImageFilter::gaussianBlur", "[benchmark]")
98{
99 SECTION("unsigned char")
100 {
102 vpImageIo::read(I, imagePath);
103
104 vpImage<double> I_blur;
105 const unsigned int kernelSize = 7;
106 const double sigma = 5.0;
107 BENCHMARK("Benchmark vpImageFilter::gaussianBlur uchar")
108 {
109 vpImageFilter::gaussianBlur(I, I_blur, kernelSize, sigma);
110 return I_blur;
111 };
112 }
113
114 SECTION("vpRGBa")
115 {
116 vpImage<vpRGBa> I, I_blur;
117 vpImageIo::read(I, imagePath);
118
119 const unsigned int kernelSize = 7;
120 const double sigma = 5.0;
121 BENCHMARK("Benchmark vpImageFilter::gaussianBlur vpRGBa")
122 {
123 vpImageFilter::gaussianBlur(I, I_blur, kernelSize, sigma);
124 return I_blur;
125 };
126 }
127}
128
129#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
130
131TEST_CASE("Gaussian filter (OpenCV)", "[benchmark]")
132{
133 SECTION("unsigned char")
134 {
135 cv::Mat img, img_blur;
136 img = cv::imread(imagePath, cv::IMREAD_GRAYSCALE);
137
138 const double sigma = 5.0;
139 BENCHMARK("Benchmark Gaussian filter uchar (OpenCV)")
140 {
141 cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
142 return img_blur;
143 };
144 }
145
146 SECTION("BGR")
147 {
148 cv::Mat img, img_blur;
149 img = cv::imread(imagePath, cv::IMREAD_COLOR);
150
151 const double sigma = 5.0;
152 BENCHMARK("Benchmark Gaussian filter BGR (OpenCV)")
153 {
154 cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
155 return img_blur;
156 };
157 }
158}
159#endif
160
161int main(int argc, char *argv[])
162{
163 Catch::Session session; // There must be exactly one instance
164
165 bool runBenchmark = false;
166 // Build a new parser on top of Catch's
167 using namespace Catch::clara;
168 auto cli = session.cli() // Get Catch's composite command line parser
169 | Opt(runBenchmark) // bind variable to a new option, with a hint string
170 ["--benchmark"] // the option names it will respond to
171 ("run benchmark?") // description string for the help output
172 ;
173
174 // Now pass the new composite back to Catch so it uses that
175 session.cli(cli);
176
177 // Let Catch (using Clara) parse the command line
178 session.applyCommandLine(argc, argv);
179
180 if (runBenchmark) {
181 int numFailed = session.run();
182
183 // numFailed is clamped to 255 as some unices only use the lower 8 bits.
184 // This clamping has already been applied, so just return it here
185 // You can also do any post run clean-up here
186 return numFailed;
187 }
188
189 return EXIT_SUCCESS;
190}
191#else
192#include <iostream>
193
194int main() { return EXIT_SUCCESS; }
195#endif
Gaussian filter class.
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
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)