#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_CATCH2
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <visp3/core/vpImageTools.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
#endif
namespace
{
}
TEST_CASE("Benchmark affine warp on grayscale image", "[benchmark]")
{
M.eye();
M[0][0] = cos(theta);
M[0][1] = -sin(theta);
M[1][0] = sin(theta);
M[1][1] = cos(theta);
BENCHMARK("Benchmark affine warp (ref code) (NN)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (fixed-point) (NN)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (ref code) (bilinear)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (fixed-point) (bilinear)")
{
return I_affine;
};
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
cv::Mat img, img_affine;
cv::Mat M_cv(2, 3, CV_64FC1);
for (unsigned int i = 0; i < M.getRows(); i++) {
for (unsigned int j = 0; j < M.getCols(); j++) {
M_cv.at<double>(i, j) = M[i][j];
}
}
BENCHMARK("Benchmark affine warp (OpenCV) (NN)")
{
cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
return img_affine;
};
BENCHMARK("Benchmark affine warp (OpenCV) (bilinear)")
{
cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
return img_affine;
};
#endif
}
TEST_CASE("Benchmark affine warp on color image", "[benchmark]")
{
M.eye();
M[0][0] = cos(theta);
M[0][1] = -sin(theta);
M[1][0] = sin(theta);
M[1][1] = cos(theta);
BENCHMARK("Benchmark affine warp (ref code) (NN)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (fixed-point) (NN)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (ref code) (bilinear)")
{
return I_affine;
};
BENCHMARK("Benchmark affine warp (fixed-point) (bilinear)")
{
return I_affine;
};
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
cv::Mat img, img_affine;
cv::Mat M_cv(2, 3, CV_64FC1);
for (unsigned int i = 0; i < M.getRows(); i++) {
for (unsigned int j = 0; j < M.getCols(); j++) {
M_cv.at<double>(i, j) = M[i][j];
}
}
BENCHMARK("Benchmark affine warp (OpenCV) (NN)")
{
cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
return img_affine;
};
BENCHMARK("Benchmark affine warp (OpenCV) (bilinear)")
{
cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
return img_affine;
};
#endif
}
TEST_CASE("Benchmark perspective warp on grayscale image", "[benchmark]")
{
M.eye();
M[0][0] = cos(theta);
M[0][1] = -sin(theta);
M[1][0] = sin(theta);
M[1][1] = cos(theta);
BENCHMARK("Benchmark perspective warp (ref code) (NN)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (fixed-point) (NN)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (ref code) (bilinear)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (fixed-point) (bilinear)")
{
return I_perspective;
};
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
cv::Mat img, img_perspective;
cv::Mat M_cv(3, 3, CV_64FC1);
for (unsigned int i = 0; i < M.getRows(); i++) {
for (unsigned int j = 0; j < M.getCols(); j++) {
M_cv.at<double>(i, j) = M[i][j];
}
}
BENCHMARK("Benchmark perspective warp (OpenCV) (NN)")
{
cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
return img_perspective;
};
BENCHMARK("Benchmark perspective warp (OpenCV) (bilinear)")
{
cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
return img_perspective;
};
#endif
}
TEST_CASE("Benchmark perspective warp on color image", "[benchmark]")
{
M.eye();
M[0][0] = cos(theta);
M[0][1] = -sin(theta);
M[1][0] = sin(theta);
M[1][1] = cos(theta);
BENCHMARK("Benchmark perspective warp (ref code) (NN)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (fixed-point) (NN)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (ref code) (bilinear)")
{
return I_perspective;
};
BENCHMARK("Benchmark perspective warp (fixed-point) (bilinear)")
{
return I_perspective;
};
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
cv::Mat img, img_perspective;
cv::Mat M_cv(3, 3, CV_64FC1);
for (unsigned int i = 0; i < M.getRows(); i++) {
for (unsigned int j = 0; j < M.getCols(); j++) {
M_cv.at<double>(i, j) = M[i][j];
}
}
BENCHMARK("Benchmark perspective warp (OpenCV) (NN)")
{
cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
return img_perspective;
};
BENCHMARK("Benchmark perspective warp (OpenCV) (bilinear)")
{
cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
return img_perspective;
};
#endif
}
int main(int argc, char *argv[])
{
Catch::Session session;
bool runBenchmark = false;
using namespace Catch::clara;
auto cli = session.cli()
| Opt(runBenchmark)
["--benchmark"]
("run benchmark?");
session.cli(cli);
session.applyCommandLine(argc, argv);
if (runBenchmark) {
int numFailed = session.run();
return numFailed;
}
return EXIT_SUCCESS;
}
#else
#include <iostream>
int main() { return EXIT_SUCCESS; }
#endif
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
unsigned int getWidth() const
unsigned int getSize() const
unsigned int getHeight() const
static double rad(double deg)
Implementation of a matrix and operations on matrices.