38 #include <visp3/core/vpConfig.h>
40 #if defined(VISP_HAVE_CATCH2)
42 #include <catch_amalgamated.hpp>
44 #include <visp3/core/vpImageTools.h>
45 #include <visp3/core/vpIoTools.h>
46 #include <visp3/io/vpImageIo.h>
48 #ifdef ENABLE_VISP_NAMESPACE
56 TEST_CASE(
"Benchmark affine warp on grayscale image",
"[benchmark]")
71 M[0][1] = -sin(theta);
77 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
83 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
89 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
95 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
101 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
102 cv::Mat img, img_affine;
106 cv::Mat M_cv(2, 3, CV_64FC1);
107 for (
unsigned int i = 0; i < M.getRows(); i++) {
108 for (
unsigned int j = 0; j < M.getCols(); j++) {
109 M_cv.at<
double>(i, j) = M[i][j];
113 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
115 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
119 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
121 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
127 TEST_CASE(
"Benchmark affine warp on color image",
"[benchmark]")
141 M[0][0] = cos(theta);
142 M[0][1] = -sin(theta);
144 M[1][0] = sin(theta);
145 M[1][1] = cos(theta);
148 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
154 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
160 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
166 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
172 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
173 cv::Mat img, img_affine;
177 cv::Mat M_cv(2, 3, CV_64FC1);
178 for (
unsigned int i = 0; i < M.getRows(); i++) {
179 for (
unsigned int j = 0; j < M.getCols(); j++) {
180 M_cv.at<
double>(i, j) = M[i][j];
184 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
186 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
190 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
192 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
198 TEST_CASE(
"Benchmark perspective warp on grayscale image",
"[benchmark]")
212 M[0][0] = cos(theta);
213 M[0][1] = -sin(theta);
215 M[1][0] = sin(theta);
216 M[1][1] = cos(theta);
219 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
222 return I_perspective;
225 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
228 return I_perspective;
231 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
234 return I_perspective;
237 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
240 return I_perspective;
243 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
244 cv::Mat img, img_perspective;
248 cv::Mat M_cv(3, 3, CV_64FC1);
249 for (
unsigned int i = 0; i < M.getRows(); i++) {
250 for (
unsigned int j = 0; j < M.getCols(); j++) {
251 M_cv.at<
double>(i, j) = M[i][j];
255 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
257 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
258 return img_perspective;
261 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
263 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
264 return img_perspective;
269 TEST_CASE(
"Benchmark perspective warp on color image",
"[benchmark]")
283 M[0][0] = cos(theta);
284 M[0][1] = -sin(theta);
286 M[1][0] = sin(theta);
287 M[1][1] = cos(theta);
290 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
293 return I_perspective;
296 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
299 return I_perspective;
302 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
305 return I_perspective;
308 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
311 return I_perspective;
314 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
315 cv::Mat img, img_perspective;
319 cv::Mat M_cv(3, 3, CV_64FC1);
320 for (
unsigned int i = 0; i < M.getRows(); i++) {
321 for (
unsigned int j = 0; j < M.getCols(); j++) {
322 M_cv.at<
double>(i, j) = M[i][j];
326 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
328 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
329 return img_perspective;
332 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
334 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
335 return img_perspective;
340 int main(
int argc,
char *argv[])
342 Catch::Session session;
343 bool runBenchmark =
false;
344 auto cli = session.cli()
345 | Catch::Clara::Opt(runBenchmark)[
"--benchmark"](
"run benchmark?");
348 session.applyCommandLine(argc, argv);
351 int numFailed = session.run();
361 int main() {
return EXIT_SUCCESS; }
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.