Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
perfGaussianFilter.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Benchmark Gaussian filter.
32 */
33
37
38#include <visp3/core/vpConfig.h>
39
40#if defined(VISP_HAVE_SIMDLIB) && defined(VISP_HAVE_CATCH2)
41
42#include <catch_amalgamated.hpp>
43
44#include <visp3/core/vpGaussianFilter.h>
45#include <visp3/core/vpImageFilter.h>
46#include <visp3/core/vpIoTools.h>
47#include <visp3/io/vpImageIo.h>
48
49#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
50#include <opencv2/imgcodecs.hpp>
51#include <opencv2/imgproc/imgproc.hpp>
52#endif
53
54#ifdef ENABLE_VISP_NAMESPACE
55using namespace VISP_NAMESPACE_NAME;
56#endif
57VP_ATTRIBUTE_NO_DESTROY static const std::string ipath = vpIoTools::getViSPImagesDataPath();
58VP_ATTRIBUTE_NO_DESTROY static std::string imagePath = vpIoTools::createFilePath(ipath, "faces/1280px-Solvay_conference_1927.png");
59
60TEST_CASE("vpGaussianFilter", "[benchmark]")
61{
62 SECTION("unsigned char")
63 {
64 vpImage<unsigned char> I, I_blur;
65 vpImageIo::read(I, imagePath);
66
67 const float sigma = 5.0f;
68 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma);
69 BENCHMARK("Benchmark vpGaussianFilter uchar")
70 {
71 gaussianFilter.apply(I, I_blur);
72 return I_blur;
73 };
74 }
75
76 SECTION("vpRGBa")
77 {
78 vpImage<vpRGBa> I, I_blur;
79 vpImageIo::read(I, imagePath);
80
81 const float sigma = 5.0f;
82 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma);
83 BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
84 {
85 gaussianFilter.apply(I, I_blur);
86 return I_blur;
87 };
88 }
89
90 SECTION("vpRGBa + deinterleave")
91 {
92 vpImage<vpRGBa> I, I_blur;
93 vpImageIo::read(I, imagePath);
94
95 const float sigma = 5.0f;
96 const bool deinterleave = true;
97 vpGaussianFilter gaussianFilter(I.getWidth(), I.getHeight(), sigma, deinterleave);
98 BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
99 {
100 gaussianFilter.apply(I, I_blur);
101 return I_blur;
102 };
103 }
104}
105
106TEST_CASE("vpImageFilter::gaussianBlur", "[benchmark]")
107{
108 SECTION("unsigned char")
109 {
111 vpImageIo::read(I, imagePath);
112
113 vpImage<double> I_blur;
114 const unsigned int kernelSize = 7;
115 const double sigma = 5.0;
116 BENCHMARK("Benchmark vpImageFilter::gaussianBlur uchar")
117 {
118 vpImageFilter::gaussianBlur(I, I_blur, kernelSize, sigma);
119 return I_blur;
120 };
121 }
122
123 SECTION("vpRGBa")
124 {
125 vpImage<vpRGBa> I, I_blur;
126 vpImageIo::read(I, imagePath);
127
128 const unsigned int kernelSize = 7;
129 const double sigma = 5.0;
130 BENCHMARK("Benchmark vpImageFilter::gaussianBlur vpRGBa")
131 {
132 vpImageFilter::gaussianBlur(I, I_blur, kernelSize, sigma);
133 return I_blur;
134 };
135 }
136}
137
138#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
139
140TEST_CASE("Gaussian filter (OpenCV)", "[benchmark]")
141{
142 SECTION("unsigned char")
143 {
144 cv::Mat img, img_blur;
145 img = cv::imread(imagePath, cv::IMREAD_GRAYSCALE);
146
147 const double sigma = 5.0;
148 BENCHMARK("Benchmark Gaussian filter uchar (OpenCV)")
149 {
150 cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
151 return img_blur;
152 };
153 }
154
155 SECTION("BGR")
156 {
157 cv::Mat img, img_blur;
158 img = cv::imread(imagePath, cv::IMREAD_COLOR);
159
160 const double sigma = 5.0;
161 BENCHMARK("Benchmark Gaussian filter BGR (OpenCV)")
162 {
163 cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
164 return img_blur;
165 };
166 }
167}
168#endif
169
170int main(int argc, char *argv[])
171{
172 Catch::Session session;
173
174 bool runBenchmark = false;
175 auto cli = session.cli()
176 | Catch::Clara::Opt(runBenchmark)["--benchmark"]("run benchmark?");
177
178 session.cli(cli);
179
180 session.applyCommandLine(argc, argv);
181
182 if (runBenchmark) {
183 int numFailed = session.run();
184
185 return numFailed;
186 }
187
188 return EXIT_SUCCESS;
189}
190#else
191#include <iostream>
192
193int main() { return EXIT_SUCCESS; }
194#endif
Gaussian filter class.
static void gaussianBlur(const vpImage< ImageType > &I, vpImage< OutputType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true, const vpImage< bool > *p_mask=nullptr)
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:131
static std::string getViSPImagesDataPath()
static std::string createFilePath(const std::string &parent, const std::string &child)