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/vpIoTools.h> 44 #include <visp3/core/vpImageTools.h> 45 #include <visp3/io/vpImageIo.h> 51 TEST_CASE(
"Benchmark affine warp on grayscale image",
"[benchmark]") {
64 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2;
65 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2;
67 BENCHMARK(
"Benchmark affine warp (ref code) (NN)") {
72 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)") {
77 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)") {
82 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)") {
87 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 88 cv::Mat img, img_affine;
92 cv::Mat M_cv(2, 3, CV_64FC1);
93 for (
unsigned int i = 0; i < M.getRows(); i++) {
94 for (
unsigned int j = 0; j < M.getCols(); j++) {
95 M_cv.at<
double>(i, j) = M[i][j];
99 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)") {
100 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
104 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)") {
105 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
111 TEST_CASE(
"Benchmark affine warp on color image",
"[benchmark]") {
124 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2;
125 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2;
127 BENCHMARK(
"Benchmark affine warp (ref code) (NN)") {
132 BENCHMARK(
"Benchmark affine warp (fixed-point) (NN)") {
137 BENCHMARK(
"Benchmark affine warp (ref code) (bilinear)") {
142 BENCHMARK(
"Benchmark affine warp (fixed-point) (bilinear)") {
147 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 148 cv::Mat img, img_affine;
152 cv::Mat M_cv(2, 3, CV_64FC1);
153 for (
unsigned int i = 0; i < M.getRows(); i++) {
154 for (
unsigned int j = 0; j < M.getCols(); j++) {
155 M_cv.at<
double>(i, j) = M[i][j];
159 BENCHMARK(
"Benchmark affine warp (OpenCV) (NN)") {
160 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_NEAREST);
164 BENCHMARK(
"Benchmark affine warp (OpenCV) (bilinear)") {
165 cv::warpAffine(img, img_affine, M_cv, img.size(), cv::INTER_LINEAR);
171 TEST_CASE(
"Benchmark perspective warp on grayscale image",
"[benchmark]") {
184 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2;
185 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2;
187 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)") {
189 return I_perspective;
192 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)") {
194 return I_perspective;
197 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)") {
199 return I_perspective;
202 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)") {
204 return I_perspective;
207 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 208 cv::Mat img, img_perspective;
212 cv::Mat M_cv(3, 3, CV_64FC1);
213 for (
unsigned int i = 0; i < M.getRows(); i++) {
214 for (
unsigned int j = 0; j < M.getCols(); j++) {
215 M_cv.at<
double>(i, j) = M[i][j];
219 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)") {
220 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
221 return img_perspective;
224 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)") {
225 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
226 return img_perspective;
231 TEST_CASE(
"Benchmark perspective warp on color image",
"[benchmark]") {
244 M[0][0] = cos(theta); M[0][1] = -sin(theta); M[0][2] = I.
getWidth() / 2;
245 M[1][0] = sin(theta); M[1][1] = cos(theta); M[1][2] = I.
getHeight() / 2;
247 BENCHMARK(
"Benchmark perspective warp (ref code) (NN)") {
249 return I_perspective;
252 BENCHMARK(
"Benchmark perspective warp (fixed-point) (NN)") {
254 return I_perspective;
257 BENCHMARK(
"Benchmark perspective warp (ref code) (bilinear)") {
259 return I_perspective;
262 BENCHMARK(
"Benchmark perspective warp (fixed-point) (bilinear)") {
264 return I_perspective;
267 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000) 268 cv::Mat img, img_perspective;
272 cv::Mat M_cv(3, 3, CV_64FC1);
273 for (
unsigned int i = 0; i < M.getRows(); i++) {
274 for (
unsigned int j = 0; j < M.getCols(); j++) {
275 M_cv.at<
double>(i, j) = M[i][j];
279 BENCHMARK(
"Benchmark perspective warp (OpenCV) (NN)") {
280 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_NEAREST);
281 return img_perspective;
284 BENCHMARK(
"Benchmark perspective warp (OpenCV) (bilinear)") {
285 cv::warpPerspective(img, img_perspective, M_cv, img.size(), cv::INTER_LINEAR);
286 return img_perspective;
291 int main(
int argc,
char *argv[])
293 Catch::Session session;
295 bool runBenchmark =
false;
297 using namespace Catch::clara;
298 auto cli = session.cli()
307 session.applyCommandLine(argc, argv);
310 int numFailed = session.run();
Implementation of a matrix and operations on matrices.
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int getSize() const
static double rad(double deg)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const