38 #include <visp3/core/vpConfig.h>
40 #if defined(VISP_HAVE_CATCH2) && defined(VISP_HAVE_THREADS)
42 #include <catch_amalgamated.hpp>
46 #include <visp3/core/vpImageTools.h>
47 #include <visp3/core/vpIoTools.h>
48 #include <visp3/io/vpImageIo.h>
50 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
51 #include <opencv2/imgcodecs.hpp>
52 #include <opencv2/imgproc/imgproc.hpp>
55 #ifdef ENABLE_VISP_NAMESPACE
61 static unsigned int g_resize_width = 293;
62 static unsigned int g_resize_height = 137;
64 TEST_CASE(
"Nearest Neighbor image resize (naive code)",
"[benchmark]")
66 SECTION(
"unsigned char")
71 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (naive code)")
73 common_tools::resizeRef(I, Iresize, common_tools::g_nearest_neighbor);
83 BENCHMARK(
"Benchmark Nearest Neighbor RGBa image resize (naive code)")
85 common_tools::resizeRef(I, Iresize, common_tools::g_nearest_neighbor);
91 TEST_CASE(
"Nearest Neighbor image resize (ViSP)",
"[benchmark]")
93 SECTION(
"unsigned char")
98 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (ViSP) (1 thread)")
104 const unsigned int nThreads = std::thread::hardware_concurrency();
105 std::stringstream buffer;
106 buffer <<
"Benchmark Nearest Neighbor uchar image resize (ViSP) (" << nThreads <<
"threads)";
107 BENCHMARK(buffer.str().c_str())
119 BENCHMARK(
"Benchmark Nearest Neighbor RGBa image resize (ViSP) (1 thread)")
125 const unsigned int nThreads = std::thread::hardware_concurrency();
126 std::stringstream buffer;
127 buffer <<
"Benchmark Nearest Neighbor RGBa image resize (ViSP) (" << nThreads <<
" threads)";
128 BENCHMARK(buffer.str().c_str())
136 TEST_CASE(
"Bilinear image resize (naive code)",
"[benchmark]")
138 SECTION(
"unsigned char")
143 BENCHMARK(
"Benchmark Bilinear uchar image resize (naive code)")
145 common_tools::resizeRef(I, Iresize, common_tools::g_bilinear);
155 BENCHMARK(
"Benchmark Bilinear RGBa image resize (naive code)")
157 common_tools::resizeRef(I, Iresize, common_tools::g_bilinear);
163 TEST_CASE(
"Bilinear image resize (ViSP)",
"[benchmark]")
165 SECTION(
"unsigned char")
170 BENCHMARK(
"Benchmark Bilinear uchar image resize (ViSP)")
182 BENCHMARK(
"Benchmark Bilinear RGBa image resize (ViSP)")
190 TEST_CASE(
"Area image resize (ViSP)",
"[benchmark]")
192 SECTION(
"unsigned char")
197 BENCHMARK(
"Benchmark Area uchar image resize (ViSP)")
209 BENCHMARK(
"Benchmark Area RGBa image resize (ViSP)")
217 TEST_CASE(
"Bicubic image resize (ViSP)",
"[benchmark]")
219 SECTION(
"unsigned char")
224 BENCHMARK(
"Benchmark Bicubic uchar image resize (ViSP) (1 thread)")
230 const unsigned int nThreads = std::thread::hardware_concurrency();
231 std::stringstream buffer;
232 buffer <<
"Benchmark Bicubic uchar image resize (ViSP) (" << nThreads <<
" threads)";
233 BENCHMARK(buffer.str().c_str())
245 BENCHMARK(
"Benchmark Bicubic RGBa image resize (ViSP) (1 thread)")
251 const unsigned int nThreads = std::thread::hardware_concurrency();
252 std::stringstream buffer;
253 buffer <<
"Benchmark Bicubic RGBa image resize (ViSP) (" << nThreads <<
" threads)";
254 BENCHMARK(buffer.str().c_str())
262 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC)
263 TEST_CASE(
"Nearest Neighbor image resize (OpenCV)",
"[benchmark]")
265 SECTION(
"unsigned char")
267 cv::Mat img, img_resize;
268 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
270 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (OpenCV)")
272 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_NEAREST);
279 cv::Mat img, img_resize;
280 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
282 BENCHMARK(
"Benchmark Nearest Neighbor BGR image resize (OpenCV)")
284 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_NEAREST);
290 TEST_CASE(
"Bilinear image resize (OpenCV)",
"[benchmark]")
292 SECTION(
"unsigned char")
294 cv::Mat img, img_resize;
295 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
297 BENCHMARK(
"Benchmark Bilinear uchar image resize (OpenCV)")
299 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_LINEAR);
306 cv::Mat img, img_resize;
307 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
309 BENCHMARK(
"Benchmark Bilinear BGR image resize (OpenCV)")
311 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_LINEAR);
317 TEST_CASE(
"Area image resize (OpenCV)",
"[benchmark]")
319 SECTION(
"unsigned char")
321 cv::Mat img, img_resize;
322 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
324 BENCHMARK(
"Benchmark Area uchar image resize (OpenCV)")
326 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_AREA);
333 cv::Mat img, img_resize;
334 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
336 BENCHMARK(
"Benchmark Area BGR image resize (OpenCV)")
338 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_AREA);
344 TEST_CASE(
"Bicubic image resize (OpenCV)",
"[benchmark]")
346 SECTION(
"unsigned char")
348 cv::Mat img, img_resize;
349 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
351 BENCHMARK(
"Benchmark Bicubic uchar image resize (OpenCV)")
353 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_CUBIC);
360 cv::Mat img, img_resize;
361 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
363 BENCHMARK(
"Benchmark Bicubic BGR image resize (OpenCV)")
365 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_CUBIC);
372 int main(
int argc,
char *argv[])
374 Catch::Session session;
376 bool runBenchmark =
false;
377 auto cli = session.cli()
378 | Catch::Clara::Opt(runBenchmark)[
"--benchmark"](
"run benchmark?")
379 | Catch::Clara::Opt(imagePathColor,
"imagePathColor")[
"--imagePathColor"](
"Path to color image")
380 | Catch::Clara::Opt(imagePathGray,
"imagePathColor")[
"--imagePathGray"]
381 | Catch::Clara::Opt(g_resize_width,
"g_resize_width")[
"--width"](
"Resize width")
382 | Catch::Clara::Opt(g_resize_height,
"g_resize_height")[
"--height"](
"Resize height");
386 session.applyCommandLine(argc, argv);
391 std::cout <<
"imagePathColor:\n\t" << imagePathColor <<
"\n\t" << I_color.
getWidth() <<
"x" << I_color.
getHeight()
396 std::cout <<
"imagePathGray:\n\t" << imagePathGray <<
"\n\t" << I_gray.
getWidth() <<
"x" << I_gray.
getHeight()
398 std::cout <<
"Resize to: " << g_resize_width <<
"x" << g_resize_height << std::endl;
400 int numFailed = session.run();
410 int main() {
return EXIT_SUCCESS; }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
unsigned int getHeight() const