36 #include <visp3/core/vpConfig.h> 38 #ifdef VISP_HAVE_CATCH2 39 #define CATCH_CONFIG_ENABLE_BENCHMARKING 40 #define CATCH_CONFIG_RUNNER 44 #include <visp3/core/vpIoTools.h> 45 #include <visp3/core/vpImageTools.h> 46 #include <visp3/io/vpImageIo.h> 52 static unsigned int g_resize_width = 293;
53 static unsigned int g_resize_height = 137;
55 TEST_CASE(
"Nearest Neighbor image resize (naive code)",
"[benchmark]") {
56 SECTION(
"unsigned char")
61 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (naive code)") {
62 common_tools::resizeRef(I, Iresize, common_tools::g_nearest_neighbor);
72 BENCHMARK(
"Benchmark Nearest Neighbor RGBa image resize (naive code)") {
73 common_tools::resizeRef(I, Iresize, common_tools::g_nearest_neighbor);
79 TEST_CASE(
"Nearest Neighbor image resize (ViSP)",
"[benchmark]") {
80 SECTION(
"unsigned char")
85 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (ViSP) (1 thread)") {
90 const unsigned int nThreads = std::thread::hardware_concurrency();
92 sprintf(buffer,
"Benchmark Nearest Neighbor uchar image resize (ViSP) (%d threads)", nThreads);
104 BENCHMARK(
"Benchmark Nearest Neighbor RGBa image resize (ViSP) (1 thread)") {
109 const unsigned int nThreads = std::thread::hardware_concurrency();
111 sprintf(buffer,
"Benchmark Nearest Neighbor RGBa image resize (ViSP) (%d threads)", nThreads);
119 TEST_CASE(
"Bilinear image resize (naive code)",
"[benchmark]") {
120 SECTION(
"unsigned char")
125 BENCHMARK(
"Benchmark Bilinear uchar image resize (naive code)") {
126 common_tools::resizeRef(I, Iresize, common_tools::g_bilinear);
136 BENCHMARK(
"Benchmark Bilinear RGBa image resize (naive code)") {
137 common_tools::resizeRef(I, Iresize, common_tools::g_bilinear);
143 TEST_CASE(
"Bilinear image resize (ViSP)",
"[benchmark]") {
144 SECTION(
"unsigned char")
149 BENCHMARK(
"Benchmark Bilinear uchar image resize (ViSP)") {
160 BENCHMARK(
"Benchmark Bilinear RGBa image resize (ViSP)") {
167 TEST_CASE(
"Area image resize (ViSP)",
"[benchmark]") {
168 SECTION(
"unsigned char")
173 BENCHMARK(
"Benchmark Area uchar image resize (ViSP)") {
184 BENCHMARK(
"Benchmark Area RGBa image resize (ViSP)") {
191 TEST_CASE(
"Bicubic image resize (ViSP)",
"[benchmark]") {
192 SECTION(
"unsigned char")
197 BENCHMARK(
"Benchmark Bicubic uchar image resize (ViSP) (1 thread)") {
202 const unsigned int nThreads = std::thread::hardware_concurrency();
204 sprintf(buffer,
"Benchmark Bicubic uchar image resize (ViSP) (%d threads)", nThreads);
216 BENCHMARK(
"Benchmark Bicubic RGBa image resize (ViSP) (1 thread)") {
221 const unsigned int nThreads = std::thread::hardware_concurrency();
223 sprintf(buffer,
"Benchmark Bicubic RGBa image resize (ViSP) (%d threads)", nThreads);
231 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 232 TEST_CASE(
"Nearest Neighbor image resize (OpenCV)",
"[benchmark]") {
233 SECTION(
"unsigned char")
235 cv::Mat img, img_resize;
236 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
238 BENCHMARK(
"Benchmark Nearest Neighbor uchar image resize (OpenCV)") {
239 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_NEAREST);
246 cv::Mat img, img_resize;
247 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
249 BENCHMARK(
"Benchmark Nearest Neighbor BGR image resize (OpenCV)") {
250 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_NEAREST);
256 TEST_CASE(
"Bilinear image resize (OpenCV)",
"[benchmark]") {
257 SECTION(
"unsigned char")
259 cv::Mat img, img_resize;
260 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
262 BENCHMARK(
"Benchmark Bilinear uchar image resize (OpenCV)") {
263 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_LINEAR);
270 cv::Mat img, img_resize;
271 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
273 BENCHMARK(
"Benchmark Bilinear BGR image resize (OpenCV)") {
274 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_LINEAR);
280 TEST_CASE(
"Area image resize (OpenCV)",
"[benchmark]") {
281 SECTION(
"unsigned char")
283 cv::Mat img, img_resize;
284 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
286 BENCHMARK(
"Benchmark Area uchar image resize (OpenCV)") {
287 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_AREA);
294 cv::Mat img, img_resize;
295 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
297 BENCHMARK(
"Benchmark Area BGR image resize (OpenCV)") {
298 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_AREA);
304 TEST_CASE(
"Bicubic image resize (OpenCV)",
"[benchmark]") {
305 SECTION(
"unsigned char")
307 cv::Mat img, img_resize;
308 img = cv::imread(imagePathGray, cv::IMREAD_GRAYSCALE);
310 BENCHMARK(
"Benchmark Bicubic uchar image resize (OpenCV)") {
311 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_CUBIC);
318 cv::Mat img, img_resize;
319 img = cv::imread(imagePathColor, cv::IMREAD_COLOR);
321 BENCHMARK(
"Benchmark Bicubic BGR image resize (OpenCV)") {
322 cv::resize(img, img_resize, cv::Size(g_resize_width, g_resize_height), 0, 0, cv::INTER_CUBIC);
329 int main(
int argc,
char *argv[])
331 Catch::Session session;
333 bool runBenchmark =
false;
335 using namespace Catch::clara;
336 auto cli = session.cli()
340 | Opt(imagePathColor,
"imagePathColor")
342 (
"Path to color image")
343 | Opt(imagePathGray,
"imagePathColor")
345 | Opt(g_resize_width,
"g_resize_width")
348 | Opt(g_resize_height,
"g_resize_height")
356 session.applyCommandLine(argc, argv);
361 std::cout <<
"imagePathColor:\n\t" << imagePathColor <<
"\n\t" << I_color.
getWidth() <<
"x" << I_color.
getHeight() << std::endl;
365 std::cout <<
"imagePathGray:\n\t" << imagePathGray <<
"\n\t" << I_gray.
getWidth() <<
"x" << I_gray.
getHeight() << std::endl;
366 std::cout <<
"Resize to: " << g_resize_width <<
"x" << g_resize_height << std::endl;
368 int numFailed = session.run();
unsigned int getWidth() const
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const