37 #include <visp3/core/vpConfig.h>
39 #if defined(VISP_HAVE_CATCH2) && defined(VISP_HAVE_THREADS)
41 #include <catch_amalgamated.hpp>
45 #include <visp3/core/vpIoTools.h>
46 #include <visp3/io/vpImageIo.h>
48 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
49 #include <opencv2/imgcodecs.hpp>
50 #include <opencv2/imgproc/imgproc.hpp>
53 #ifdef ENABLE_VISP_NAMESPACE
59 static int nThreads = 0;
61 TEST_CASE(
"Benchmark rgba to grayscale (naive code)",
"[benchmark]")
68 BENCHMARK(
"Benchmark rgba to grayscale (naive code)")
70 common_tools::RGBaToGrayRef(
reinterpret_cast<unsigned char *
>(I.
bitmap), I_gray.bitmap, I.
getSize());
75 TEST_CASE(
"Benchmark rgba to grayscale (ViSP)",
"[benchmark]")
82 BENCHMARK(
"Benchmark rgba to grayscale (ViSP)")
89 TEST_CASE(
"Benchmark grayscale to rgba (naive code)",
"[benchmark]")
96 BENCHMARK(
"Benchmark grayscale to rgba (naive code)")
98 common_tools::grayToRGBaRef(I.
bitmap,
reinterpret_cast<unsigned char *
>(I_color.bitmap), I.
getSize());
103 TEST_CASE(
"Benchmark grayscale to rgba (ViSP)",
"[benchmark]")
110 BENCHMARK(
"Benchmark grayscale to rgba (ViSP)")
117 TEST_CASE(
"Benchmark split RGBa (ViSP)",
"[benchmark]")
123 BENCHMARK(
"Benchmark split RGBa (ViSP)")
130 TEST_CASE(
"Benchmark merge to RGBa (ViSP)",
"[benchmark]")
139 BENCHMARK(
"Benchmark merge to RGBa (ViSP)")
146 TEST_CASE(
"Benchmark bgr to grayscale (naive code)",
"[benchmark]")
151 std::vector<unsigned char> bgr;
152 common_tools::RGBaToBGR(I, bgr);
156 BENCHMARK(
"Benchmark bgr to grayscale (naive code)")
158 common_tools::BGRToGrayRef(bgr.data(),
reinterpret_cast<unsigned char *
>(I_gray.bitmap), I_gray.getWidth(),
159 I_gray.getHeight(),
false);
164 TEST_CASE(
"Benchmark bgr to grayscale (ViSP)",
"[benchmark]")
169 std::vector<unsigned char> bgr;
170 common_tools::RGBaToBGR(I, bgr);
174 BENCHMARK(
"Benchmark bgr to grayscale (ViSP)")
180 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC)
182 SECTION(
"OpenCV Mat type")
187 BENCHMARK(
"Benchmark bgr to grayscale (ViSP + OpenCV Mat type)")
196 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
197 TEST_CASE(
"Benchmark bgr to grayscale (OpenCV)",
"[benchmark]")
199 cv::Mat img = cv::imread(imagePathColor);
200 cv::Mat img_gray(img.size(), CV_8UC1);
202 BENCHMARK(
"Benchmark bgr to grayscale (OpenCV)")
204 cv::cvtColor(img, img_gray, cv::COLOR_BGR2GRAY);
210 TEST_CASE(
"Benchmark bgr to rgba (naive code)",
"[benchmark]")
215 std::vector<unsigned char> bgr;
216 common_tools::RGBaToBGR(I, bgr);
219 BENCHMARK(
"Benchmark bgr to rgba (naive code)")
221 common_tools::BGRToRGBaRef(bgr.data(),
reinterpret_cast<unsigned char *
>(I_bench.bitmap), I.
getWidth(),
227 TEST_CASE(
"Benchmark bgr to rgba (ViSP)",
"[benchmark]")
232 std::vector<unsigned char> bgr;
233 common_tools::RGBaToBGR(I, bgr);
235 SECTION(
"Check BGR to RGBa conversion")
238 common_tools::BGRToRGBaRef(bgr.data(),
reinterpret_cast<unsigned char *
>(ref.bitmap), I.
getWidth(), I.
getHeight(),
244 CHECK((rgba == ref));
248 BENCHMARK(
"Benchmark bgr to rgba (ViSP)")
255 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC)
256 SECTION(
"OpenCV Mat type")
261 BENCHMARK(
"Benchmark bgr to rgba (ViSP + OpenCV Mat type)")
270 TEST_CASE(
"Benchmark bgra to rgba (naive code)",
"[benchmark]")
275 std::vector<unsigned char> bgra;
276 common_tools::RGBaToBGRa(I, bgra);
279 BENCHMARK(
"Benchmark bgra to rgba (naive code)")
281 common_tools::BGRaToRGBaRef(bgra.data(),
reinterpret_cast<unsigned char *
>(I_bench.bitmap), I.
getWidth(),
287 TEST_CASE(
"Benchmark bgra to rgba (ViSP)",
"[benchmark]")
292 std::vector<unsigned char> bgra;
293 common_tools::RGBaToBGRa(I, bgra);
295 SECTION(
"Check BGRa to RGBa conversion")
298 common_tools::BGRaToRGBaRef(bgra.data(),
reinterpret_cast<unsigned char *
>(ref.bitmap), I.
getWidth(), I.
getHeight(),
304 CHECK((rgba == ref));
307 BENCHMARK(
"Benchmark bgra to rgba (ViSP)")
315 int main(
int argc,
char *argv[])
317 Catch::Session session;
319 bool runBenchmark =
false;
320 auto cli = session.cli()
321 | Catch::Clara::Opt(runBenchmark)[
"--benchmark"](
"run benchmark?")
322 | Catch::Clara::Opt(imagePathColor,
"imagePathColor")[
"--imagePathColor"](
"Path to color image")
323 | Catch::Clara::Opt(imagePathGray,
"imagePathColor")[
"--imagePathGray"](
"Path to gray image")
324 | Catch::Clara::Opt(nThreads,
"nThreads")[
"--nThreads"](
"Number of threads");
328 session.applyCommandLine(argc, argv);
333 std::cout <<
"imagePathColor:\n\t" << imagePathColor <<
"\n\t" << I_color.
getWidth() <<
"x" << I_color.
getHeight()
338 std::cout <<
"imagePathGray:\n\t" << imagePathGray <<
"\n\t" << I_gray.
getWidth() <<
"x" << I_gray.
getHeight()
340 std::cout <<
"nThreads: " << nThreads <<
" / available threads: " << std::thread::hardware_concurrency()
343 int numFailed = session.run();
353 int main() {
return EXIT_SUCCESS; }
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