#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_SIMDLIB) && defined(VISP_HAVE_CATCH2)
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <visp3/core/vpGaussianFilter.h>
#include <visp3/core/vpImageFilter.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#ifdef ENABLE_VISP_NAMESPACE
#endif
TEST_CASE("vpGaussianFilter", "[benchmark]")
{
SECTION("unsigned char")
{
const float sigma = 5.0f;
BENCHMARK("Benchmark vpGaussianFilter uchar")
{
gaussianFilter.apply(I, I_blur);
return I_blur;
};
}
SECTION("vpRGBa")
{
const float sigma = 5.0f;
BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
{
gaussianFilter.apply(I, I_blur);
return I_blur;
};
}
SECTION("vpRGBa + deinterleave")
{
const float sigma = 5.0f;
const bool deinterleave = true;
BENCHMARK("Benchmark vpGaussianFilter vpRGBa")
{
gaussianFilter.apply(I, I_blur);
return I_blur;
};
}
}
TEST_CASE("vpImageFilter::gaussianBlur", "[benchmark]")
{
SECTION("unsigned char")
{
const unsigned int kernelSize = 7;
const double sigma = 5.0;
BENCHMARK("Benchmark vpImageFilter::gaussianBlur uchar")
{
return I_blur;
};
}
SECTION("vpRGBa")
{
const unsigned int kernelSize = 7;
const double sigma = 5.0;
BENCHMARK("Benchmark vpImageFilter::gaussianBlur vpRGBa")
{
return I_blur;
};
}
}
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
TEST_CASE("Gaussian filter (OpenCV)", "[benchmark]")
{
SECTION("unsigned char")
{
cv::Mat img, img_blur;
img = cv::imread(imagePath, cv::IMREAD_GRAYSCALE);
const double sigma = 5.0;
BENCHMARK("Benchmark Gaussian filter uchar (OpenCV)")
{
cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
return img_blur;
};
}
SECTION("BGR")
{
cv::Mat img, img_blur;
img = cv::imread(imagePath, cv::IMREAD_COLOR);
const double sigma = 5.0;
BENCHMARK("Benchmark Gaussian filter BGR (OpenCV)")
{
cv::GaussianBlur(img, img_blur, cv::Size(), sigma);
return img_blur;
};
}
}
#endif
int main(int argc, char *argv[])
{
Catch::Session session;
bool runBenchmark = false;
using namespace Catch::clara;
auto cli = session.cli()
| Opt(runBenchmark)
["--benchmark"]
("run benchmark?")
;
session.cli(cli);
session.applyCommandLine(argc, argv);
if (runBenchmark) {
int numFailed = session.run();
return numFailed;
}
return EXIT_SUCCESS;
}
#else
#include <iostream>
int main() { return EXIT_SUCCESS; }
#endif
static void gaussianBlur(const vpImage< ImageType > &I, vpImage< FilterType > &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)
unsigned int getWidth() const
unsigned int getHeight() const