38 #include <visp3/core/vpConfig.h>
40 #ifdef VISP_HAVE_CATCH2
41 #define CATCH_CONFIG_ENABLE_BENCHMARKING
42 #define CATCH_CONFIG_RUNNER
45 #include <visp3/core/vpImageTools.h>
46 #include <visp3/core/vpIoTools.h>
47 #include <visp3/io/vpImageIo.h>
49 #ifdef ENABLE_VISP_NAMESPACE
57 TEST_CASE(
"Benchmark affine warp on grayscale image",
"[benchmark]")
72 M[0][1] = -sin(theta);
78 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
84 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
90 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
96 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
102 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
103 cv::Mat img, img_affine;
107 cv::Mat M_cv(2, 3, CV_64FC1);
108 for (
unsigned int i = 0; i < M.getRows(); i++) {
109 for (
unsigned int j = 0; j < M.getCols(); j++) {
110 M_cv.at<
double>(i, j) = M[i][j];
114 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
116 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
120 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
122 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
128 TEST_CASE(
"Benchmark affine warp on color image",
"[benchmark]")
142 M[0][0] = cos(theta);
143 M[0][1] = -sin(theta);
145 M[1][0] = sin(theta);
146 M[1][1] = cos(theta);
149 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
155 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
161 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
167 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
173 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
174 cv::Mat img, img_affine;
178 cv::Mat M_cv(2, 3, CV_64FC1);
179 for (
unsigned int i = 0; i < M.getRows(); i++) {
180 for (
unsigned int j = 0; j < M.getCols(); j++) {
181 M_cv.at<
double>(i, j) = M[i][j];
185 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
187 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
191 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
193 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
199 TEST_CASE(
"Benchmark perspective warp on grayscale image",
"[benchmark]")
213 M[0][0] = cos(theta);
214 M[0][1] = -sin(theta);
216 M[1][0] = sin(theta);
217 M[1][1] = cos(theta);
220 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
223 return I_perspective;
226 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
229 return I_perspective;
232 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
235 return I_perspective;
238 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
241 return I_perspective;
244 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
245 cv::Mat img, img_perspective;
249 cv::Mat M_cv(3, 3, CV_64FC1);
250 for (
unsigned int i = 0; i < M.getRows(); i++) {
251 for (
unsigned int j = 0; j < M.getCols(); j++) {
252 M_cv.at<
double>(i, j) = M[i][j];
256 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
258 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
259 return img_perspective;
262 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
264 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
265 return img_perspective;
270 TEST_CASE(
"Benchmark perspective warp on color image",
"[benchmark]")
284 M[0][0] = cos(theta);
285 M[0][1] = -sin(theta);
287 M[1][0] = sin(theta);
288 M[1][1] = cos(theta);
291 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
294 return I_perspective;
297 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
300 return I_perspective;
303 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
306 return I_perspective;
309 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
312 return I_perspective;
315 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
316 cv::Mat img, img_perspective;
320 cv::Mat M_cv(3, 3, CV_64FC1);
321 for (
unsigned int i = 0; i < M.getRows(); i++) {
322 for (
unsigned int j = 0; j < M.getCols(); j++) {
323 M_cv.at<
double>(i, j) = M[i][j];
327 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
329 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
330 return img_perspective;
333 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
335 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
336 return img_perspective;
341 int main(
int argc,
char *argv[])
343 Catch::Session session;
345 bool runBenchmark =
false;
347 using namespace Catch::clara;
348 auto cli = session.cli()
357 session.applyCommandLine(argc, argv);
360 int numFailed = session.run();
373 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.