#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2) && defined(VISP_HAVE_THREADS)
#include <catch_amalgamated.hpp>
#include <thread>
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
#endif
static std::vector<std::string> paths {
ipath + "/Solvay/Solvay_conference_1927_Version2_640x440",
ipath + "/Solvay/Solvay_conference_1927_Version2_1024x705",
ipath + "/Solvay/Solvay_conference_1927_Version2_1280x881",
ipath + "/Solvay/Solvay_conference_1927_Version2_2126x1463",
};
static std::vector<std::string> names { "Solvay (640x440)", "Solvay (1024x705)", "Solvay (1280x881)",
"Solvay (2126x1463)" };
static std::vector<vpImageIo::vpImageIoBackendType> backends
{
#if defined(VISP_HAVE_JPEG) && defined(VISP_HAVE_PNG)
#endif
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
#endif
#if defined(VISP_HAVE_SIMDLIB)
#endif
};
static std::vector<std::string> backendNamesJpeg
{
#if defined(VISP_HAVE_JPEG)
"libjpeg",
#endif
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
"OpenCV",
#endif
"simd", "stb"
};
static std::vector<std::string> backendNamesPng
{
#if defined(VISP_HAVE_PNG)
"libpng",
#endif
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
"OpenCV",
#endif
"simd", "stb"
};
static int nThreads = 0;
TEST_CASE("Benchmark grayscale JPEG image loading", "[benchmark]")
{
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesJpeg[j] + " backend")
{
return I;
};
}
}
}
}
TEST_CASE("Benchmark RGBA JPEG image loading", "[benchmark]")
{
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesJpeg[j] + " backend")
{
return I;
};
}
}
}
}
TEST_CASE("Benchmark grayscale PNG image loading", "[benchmark]")
{
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesPng[j] + " backend")
{
return I;
};
}
}
}
}
TEST_CASE("Benchmark RGBA PNG image loading", "[benchmark]")
{
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesPng[j] + " backend")
{
return I;
};
}
}
}
}
TEST_CASE("Benchmark grayscale JPEG image saving", "[benchmark]")
{
std::string directory_filename_tmp =
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesJpeg[j] + " backend")
{
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg", backends[j]);
return I;
};
}
}
}
}
TEST_CASE("Benchmark RGBA JPEG image saving", "[benchmark]")
{
std::string directory_filename_tmp =
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesJpeg[j] + " backend")
{
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.jpg", backends[j]);
return I;
};
}
}
}
}
TEST_CASE("Benchmark grayscale PNG image saving", "[benchmark]")
{
std::string directory_filename_tmp =
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesPng[j] + " backend")
{
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.png", backends[j]);
return I;
};
}
}
}
}
TEST_CASE("Benchmark RGBA PNG image saving", "[benchmark]")
{
std::string directory_filename_tmp =
for (size_t i = 0; i < paths.size(); i++) {
SECTION(names[i])
{
for (size_t j = 0; j < backends.size(); j++) {
BENCHMARK(backendNamesPng[j] + " backend")
{
vpImageIo::write(I, directory_filename_tmp +
"/ViSP_tmp_perf_write.png", backends[j]);
return I;
};
}
}
}
}
int main(int argc, char *argv[])
{
Catch::Session session;
bool runBenchmark = false;
auto cli = session.cli()
| Catch::Clara::Opt(runBenchmark)["--benchmark"]("Run benchmark")
| Catch::Clara::Opt(nThreads, "nThreads")["--nThreads"]("Number of threads");
session.cli(cli);
session.applyCommandLine(argc, argv);
if (runBenchmark) {
std::cout << "nThreads: " << nThreads << " / available threads: " << std::thread::hardware_concurrency() << std::endl;
int numFailed = session.run();
return numFailed;
}
return EXIT_SUCCESS;
}
#else
#include <iostream>
int main() { return EXIT_SUCCESS; }
#endif
@ IO_STB_IMAGE_BACKEND
Use embedded stb_image library.
@ IO_SIMDLIB_BACKEND
Use embedded simd library.
@ IO_SYSTEM_LIB_BACKEND
Use system libraries like libpng or libjpeg-turbo.
@ IO_OPENCV_BACKEND
Use OpenCV imgcodecs module.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")