36 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_CATCH2
39 #define CATCH_CONFIG_ENABLE_BENCHMARKING
40 #define CATCH_CONFIG_RUNNER
43 #include <visp3/core/vpImageTools.h>
44 #include <visp3/core/vpIoTools.h>
45 #include <visp3/io/vpImageIo.h>
52 TEST_CASE(
"Benchmark affine warp on grayscale image",
"[benchmark]")
67 M[0][1] = -sin(theta);
73 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
79 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
85 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
91 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
97 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
98 cv::Mat img, img_affine;
102 cv::Mat M_cv(2, 3, CV_64FC1);
103 for (
unsigned int i = 0; i < M.getRows(); i++) {
104 for (
unsigned int j = 0; j < M.getCols(); j++) {
105 M_cv.at<
double>(i, j) = M[i][j];
109 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
111 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
115 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
117 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
123 TEST_CASE(
"Benchmark affine warp on color image",
"[benchmark]")
137 M[0][0] = cos(theta);
138 M[0][1] = -sin(theta);
140 M[1][0] = sin(theta);
141 M[1][1] = cos(theta);
144 BENCHMARK(
"Benchmark affine warp (ref code) (NN)")
150 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)")
156 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)")
162 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)")
168 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
169 cv::Mat img, img_affine;
173 cv::Mat M_cv(2, 3, CV_64FC1);
174 for (
unsigned int i = 0; i < M.getRows(); i++) {
175 for (
unsigned int j = 0; j < M.getCols(); j++) {
176 M_cv.at<
double>(i, j) = M[i][j];
180 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)")
182 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
186 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)")
188 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
194 TEST_CASE(
"Benchmark perspective warp on grayscale image",
"[benchmark]")
208 M[0][0] = cos(theta);
209 M[0][1] = -sin(theta);
211 M[1][0] = sin(theta);
212 M[1][1] = cos(theta);
215 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
218 return I_perspective;
221 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
224 return I_perspective;
227 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
230 return I_perspective;
233 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
236 return I_perspective;
239 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
240 cv::Mat img, img_perspective;
244 cv::Mat M_cv(3, 3, CV_64FC1);
245 for (
unsigned int i = 0; i < M.getRows(); i++) {
246 for (
unsigned int j = 0; j < M.getCols(); j++) {
247 M_cv.at<
double>(i, j) = M[i][j];
251 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
253 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
254 return img_perspective;
257 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
259 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
260 return img_perspective;
265 TEST_CASE(
"Benchmark perspective warp on color image",
"[benchmark]")
279 M[0][0] = cos(theta);
280 M[0][1] = -sin(theta);
282 M[1][0] = sin(theta);
283 M[1][1] = cos(theta);
286 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)")
289 return I_perspective;
292 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)")
295 return I_perspective;
298 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)")
301 return I_perspective;
304 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)")
307 return I_perspective;
310 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGPROC)
311 cv::Mat img, img_perspective;
315 cv::Mat M_cv(3, 3, CV_64FC1);
316 for (
unsigned int i = 0; i < M.getRows(); i++) {
317 for (
unsigned int j = 0; j < M.getCols(); j++) {
318 M_cv.at<
double>(i, j) = M[i][j];
322 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)")
324 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
325 return img_perspective;
328 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)")
330 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
331 return img_perspective;
336 int main(
int argc,
char *argv[])
338 Catch::Session session;
340 bool runBenchmark =
false;
342 using namespace Catch::clara;
343 auto cli = session.cli()
352 session.applyCommandLine(argc, argv);
355 int numFailed = session.run();
368 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.