#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_CATCH2) && defined(VISP_HAVE_THREADS)
#include <catch_amalgamated.hpp>
#include "common.hpp"
#include <thread>
#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
static int nThreads = 0;
TEST_CASE("Benchmark rgba to grayscale (naive code)", "[benchmark]")
{
BENCHMARK("Benchmark rgba to grayscale (naive code)")
{
common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(I.
bitmap), I_gray.bitmap, I.
getSize());
return I_gray;
};
}
TEST_CASE("Benchmark rgba to grayscale (ViSP)", "[benchmark]")
{
BENCHMARK("Benchmark rgba to grayscale (ViSP)")
{
return I_gray;
};
}
TEST_CASE("Benchmark grayscale to rgba (naive code)", "[benchmark]")
{
BENCHMARK("Benchmark grayscale to rgba (naive code)")
{
common_tools::grayToRGBaRef(I.
bitmap,
reinterpret_cast<unsigned char *
>(I_color.bitmap), I.
getSize());
return I_color;
};
}
TEST_CASE("Benchmark grayscale to rgba (ViSP)", "[benchmark]")
{
BENCHMARK("Benchmark grayscale to rgba (ViSP)")
{
return I_color;
};
}
TEST_CASE("Benchmark split RGBa (ViSP)", "[benchmark]")
{
BENCHMARK("Benchmark split RGBa (ViSP)")
{
return R;
};
}
TEST_CASE("Benchmark merge to RGBa (ViSP)", "[benchmark]")
{
BENCHMARK("Benchmark merge to RGBa (ViSP)")
{
return I_merge;
};
}
TEST_CASE("Benchmark bgr to grayscale (naive code)", "[benchmark]")
{
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(I, bgr);
BENCHMARK("Benchmark bgr to grayscale (naive code)")
{
common_tools::BGRToGrayRef(bgr.data(), reinterpret_cast<unsigned char *>(I_gray.bitmap), I_gray.getWidth(),
I_gray.getHeight(), false);
return I_gray;
};
}
TEST_CASE("Benchmark bgr to grayscale (ViSP)", "[benchmark]")
{
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(I, bgr);
BENCHMARK("Benchmark bgr to grayscale (ViSP)")
{
return I_gray;
};
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC)
SECTION("OpenCV Mat type")
{
cv::Mat img;
BENCHMARK("Benchmark bgr to grayscale (ViSP + OpenCV Mat type)")
{
return I_gray;
};
}
#endif
}
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
TEST_CASE("Benchmark bgr to grayscale (OpenCV)", "[benchmark]")
{
cv::Mat img = cv::imread(imagePathColor);
cv::Mat img_gray(img.size(), CV_8UC1);
BENCHMARK("Benchmark bgr to grayscale (OpenCV)")
{
cv::cvtColor(img, img_gray, cv::COLOR_BGR2GRAY);
return img_gray;
};
}
#endif
TEST_CASE("Benchmark bgr to rgba (naive code)", "[benchmark]")
{
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(I, bgr);
BENCHMARK("Benchmark bgr to rgba (naive code)")
{
common_tools::BGRToRGBaRef(bgr.data(),
reinterpret_cast<unsigned char *
>(I_bench.bitmap), I.
getWidth(),
return I_bench;
};
}
TEST_CASE("Benchmark bgr to rgba (ViSP)", "[benchmark]")
{
std::vector<unsigned char> bgr;
common_tools::RGBaToBGR(I, bgr);
SECTION("Check BGR to RGBa conversion")
{
common_tools::BGRToRGBaRef(bgr.data(),
reinterpret_cast<unsigned char *
>(ref.bitmap), I.
getWidth(), I.
getHeight(),
false);
false);
CHECK((rgba == ref));
}
BENCHMARK("Benchmark bgr to rgba (ViSP)")
{
false);
return I_rgba;
};
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC)
SECTION("OpenCV Mat type")
{
cv::Mat img;
BENCHMARK("Benchmark bgr to rgba (ViSP + OpenCV Mat type)")
{
return I_rgba;
};
}
#endif
}
TEST_CASE("Benchmark bgra to rgba (naive code)", "[benchmark]")
{
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(I, bgra);
BENCHMARK("Benchmark bgra to rgba (naive code)")
{
common_tools::BGRaToRGBaRef(bgra.data(),
reinterpret_cast<unsigned char *
>(I_bench.bitmap), I.
getWidth(),
return I_bench;
};
}
TEST_CASE("Benchmark bgra to rgba (ViSP)", "[benchmark]")
{
std::vector<unsigned char> bgra;
common_tools::RGBaToBGRa(I, bgra);
SECTION("Check BGRa to RGBa conversion")
{
common_tools::BGRaToRGBaRef(bgra.data(),
reinterpret_cast<unsigned char *
>(ref.bitmap), I.
getWidth(), I.
getHeight(),
false);
false);
CHECK((rgba == ref));
}
BENCHMARK("Benchmark bgra to rgba (ViSP)")
{
return I_rgba;
};
}
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(imagePathColor, "imagePathColor")["--imagePathColor"]("Path to color image")
| Catch::Clara::Opt(imagePathGray, "imagePathColor")["--imagePathGray"]("Path to gray image")
| Catch::Clara::Opt(nThreads, "nThreads")["--nThreads"]("Number of threads");
session.cli(cli);
session.applyCommandLine(argc, argv);
if (runBenchmark) {
std::cout <<
"imagePathColor:\n\t" << imagePathColor <<
"\n\t" << I_color.
getWidth() <<
"x" << I_color.
getHeight()
<< std::endl;
std::cout <<
"imagePathGray:\n\t" << imagePathGray <<
"\n\t" << I_gray.
getWidth() <<
"x" << I_gray.
getHeight()
<< std::endl;
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
static void merge(const vpImage< unsigned char > *R, const vpImage< unsigned char > *G, const vpImage< unsigned char > *B, const vpImage< unsigned char > *a, vpImage< vpRGBa > &RGBa)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=nullptr)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const