Visual Servoing Platform  version 3.6.1 under development (2024-04-30)
perfApriltagDetection.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Apriltag detection performance test.
33  *
34 *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 
38 #if defined(VISP_HAVE_CATCH2)
39 #define CATCH_CONFIG_ENABLE_BENCHMARKING
40 #define CATCH_CONFIG_RUNNER
41 #include <catch.hpp>
42 
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/detection/vpDetectorAprilTag.h>
45 #include <visp3/io/vpImageIo.h>
46 
47 TEST_CASE("Benchmark Apriltag detection 1920x1080", "[benchmark]")
48 {
49  const double tagSize = 0.25;
50  const vpCameraParameters cam(2100, 2100, 960, 540);
51  const size_t nbTags = 5;
52 
53  SECTION("tag16_05")
54  {
56  "AprilTag/benchmark/1920x1080/tag16_05_1920x1080.png");
57  REQUIRE(vpIoTools::checkFilename(filename));
59  vpImageIo::read(I, filename);
60 
62  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080")
63  {
64  std::vector<vpHomogeneousMatrix> cMo_vec;
65  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
66  CHECK(cMo_vec.size() == nbTags);
67  return cMo_vec;
68  };
69 
70  apriltag_detector.setAprilTagQuadDecimate(2);
71  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=2")
72  {
73  std::vector<vpHomogeneousMatrix> cMo_vec;
74  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
75  CHECK(cMo_vec.size() == nbTags);
76  return cMo_vec;
77  };
78 
79  apriltag_detector.setAprilTagQuadDecimate(3);
80  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=3")
81  {
82  std::vector<vpHomogeneousMatrix> cMo_vec;
83  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
84  CHECK(cMo_vec.size() == nbTags);
85  return cMo_vec;
86  };
87  }
88 
89  SECTION("tag25_09")
90  {
92  "AprilTag/benchmark/1920x1080/tag25_09_1920x1080.png");
93  REQUIRE(vpIoTools::checkFilename(filename));
95  vpImageIo::read(I, filename);
96 
98  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080")
99  {
100  std::vector<vpHomogeneousMatrix> cMo_vec;
101  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
102  CHECK(cMo_vec.size() == nbTags);
103  return cMo_vec;
104  };
105 
106  apriltag_detector.setAprilTagQuadDecimate(2);
107  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=2")
108  {
109  std::vector<vpHomogeneousMatrix> cMo_vec;
110  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
111  CHECK(cMo_vec.size() == nbTags);
112  return cMo_vec;
113  };
114 
115  apriltag_detector.setAprilTagQuadDecimate(3);
116  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=3")
117  {
118  std::vector<vpHomogeneousMatrix> cMo_vec;
119  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
120  CHECK(cMo_vec.size() == nbTags);
121  return cMo_vec;
122  };
123  }
124 
125  SECTION("tag36_11")
126  {
128  "AprilTag/benchmark/1920x1080/tag36_11_1920x1080.png");
129  REQUIRE(vpIoTools::checkFilename(filename));
131  vpImageIo::read(I, filename);
132 
134  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080")
135  {
136  std::vector<vpHomogeneousMatrix> cMo_vec;
137  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
138  CHECK(cMo_vec.size() == nbTags);
139  return cMo_vec;
140  };
141 
142  apriltag_detector.setAprilTagQuadDecimate(2);
143  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=2")
144  {
145  std::vector<vpHomogeneousMatrix> cMo_vec;
146  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
147  CHECK(cMo_vec.size() == nbTags);
148  return cMo_vec;
149  };
150 
151  apriltag_detector.setAprilTagQuadDecimate(3);
152  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=3")
153  {
154  std::vector<vpHomogeneousMatrix> cMo_vec;
155  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
156  CHECK(cMo_vec.size() == nbTags);
157  return cMo_vec;
158  };
159  }
160 
161  SECTION("tag21_07")
162  {
164  "AprilTag/benchmark/1920x1080/tag21_07_1920x1080.png");
165  REQUIRE(vpIoTools::checkFilename(filename));
167  vpImageIo::read(I, filename);
168 
170  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080")
171  {
172  std::vector<vpHomogeneousMatrix> cMo_vec;
173  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
174  CHECK(cMo_vec.size() == nbTags);
175  return cMo_vec;
176  };
177 
178  apriltag_detector.setAprilTagQuadDecimate(2);
179  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=2")
180  {
181  std::vector<vpHomogeneousMatrix> cMo_vec;
182  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
183  CHECK(cMo_vec.size() == nbTags);
184  return cMo_vec;
185  };
186 
187  apriltag_detector.setAprilTagQuadDecimate(3);
188  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=3")
189  {
190  std::vector<vpHomogeneousMatrix> cMo_vec;
191  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
192  CHECK(cMo_vec.size() == nbTags);
193  return cMo_vec;
194  };
195  }
196 
197 #if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
198  SECTION("tag49_12")
199  {
201  "AprilTag/benchmark/1920x1080/tag49_12_1920x1080.png");
202  REQUIRE(vpIoTools::checkFilename(filename));
204  vpImageIo::read(I, filename);
205 
207  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080")
208  {
209  std::vector<vpHomogeneousMatrix> cMo_vec;
210  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
211  CHECK(cMo_vec.size() == nbTags);
212  return cMo_vec;
213  };
214 
215  apriltag_detector.setAprilTagQuadDecimate(2);
216  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=2")
217  {
218  std::vector<vpHomogeneousMatrix> cMo_vec;
219  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
220  CHECK(cMo_vec.size() == nbTags);
221  return cMo_vec;
222  };
223 
224  apriltag_detector.setAprilTagQuadDecimate(3);
225  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=3")
226  {
227  std::vector<vpHomogeneousMatrix> cMo_vec;
228  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
229  CHECK(cMo_vec.size() == nbTags);
230  return cMo_vec;
231  };
232  }
233 
234  SECTION("tag48_12")
235  {
237  "AprilTag/benchmark/1920x1080/tag48_12_1920x1080.png");
238  REQUIRE(vpIoTools::checkFilename(filename));
240  vpImageIo::read(I, filename);
241 
243  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080")
244  {
245  std::vector<vpHomogeneousMatrix> cMo_vec;
246  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
247  CHECK(cMo_vec.size() == nbTags);
248  return cMo_vec;
249  };
250 
251  apriltag_detector.setAprilTagQuadDecimate(2);
252  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=2")
253  {
254  std::vector<vpHomogeneousMatrix> cMo_vec;
255  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
256  CHECK(cMo_vec.size() == nbTags);
257  return cMo_vec;
258  };
259 
260  apriltag_detector.setAprilTagQuadDecimate(3);
261  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=3")
262  {
263  std::vector<vpHomogeneousMatrix> cMo_vec;
264  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
265  CHECK(cMo_vec.size() == nbTags);
266  return cMo_vec;
267  };
268  }
269 
270  SECTION("tag41_12")
271  {
273  "AprilTag/benchmark/1920x1080/tag41_12_1920x1080.png");
274  REQUIRE(vpIoTools::checkFilename(filename));
276  vpImageIo::read(I, filename);
277 
279  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080")
280  {
281  std::vector<vpHomogeneousMatrix> cMo_vec;
282  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
283  CHECK(cMo_vec.size() == nbTags);
284  return cMo_vec;
285  };
286 
287  apriltag_detector.setAprilTagQuadDecimate(2);
288  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=2")
289  {
290  std::vector<vpHomogeneousMatrix> cMo_vec;
291  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
292  CHECK(cMo_vec.size() == nbTags);
293  return cMo_vec;
294  };
295 
296  apriltag_detector.setAprilTagQuadDecimate(3);
297  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=3")
298  {
299  std::vector<vpHomogeneousMatrix> cMo_vec;
300  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
301  CHECK(cMo_vec.size() == nbTags);
302  return cMo_vec;
303  };
304  }
305 
306  SECTION("tag52_13")
307  {
309  "AprilTag/benchmark/1920x1080/tag52_13_1920x1080.png");
310  REQUIRE(vpIoTools::checkFilename(filename));
312  vpImageIo::read(I, filename);
313 
315  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080")
316  {
317  std::vector<vpHomogeneousMatrix> cMo_vec;
318  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
319  CHECK(cMo_vec.size() == nbTags);
320  return cMo_vec;
321  };
322 
323  apriltag_detector.setAprilTagQuadDecimate(2);
324  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=2")
325  {
326  std::vector<vpHomogeneousMatrix> cMo_vec;
327  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
328  CHECK(cMo_vec.size() == nbTags);
329  return cMo_vec;
330  };
331 
332  apriltag_detector.setAprilTagQuadDecimate(3);
333  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=3")
334  {
335  std::vector<vpHomogeneousMatrix> cMo_vec;
336  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
337  CHECK(cMo_vec.size() == nbTags);
338  return cMo_vec;
339  };
340  }
341 #endif
342 }
343 
344 TEST_CASE("Benchmark Apriltag detection 640x480", "[benchmark]")
345 {
346  const double tagSize = 0.25;
347  const vpCameraParameters cam(700, 700, 320, 240);
348  const size_t nbTags = 5;
349 
350  SECTION("tag16_05")
351  {
353  "AprilTag/benchmark/640x480/tag16_05_640x480.png");
354  REQUIRE(vpIoTools::checkFilename(filename));
356  vpImageIo::read(I, filename);
357 
359  BENCHMARK("Benchmark Apriltag detection: tag16_05 640x480")
360  {
361  std::vector<vpHomogeneousMatrix> cMo_vec;
362  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
363  CHECK(cMo_vec.size() == nbTags);
364  return cMo_vec;
365  };
366  }
367 
368  SECTION("tag25_09")
369  {
371  "AprilTag/benchmark/640x480/tag25_09_640x480.png");
372  REQUIRE(vpIoTools::checkFilename(filename));
374  vpImageIo::read(I, filename);
375 
377  BENCHMARK("Benchmark Apriltag detection: tag25_09 640x480")
378  {
379  std::vector<vpHomogeneousMatrix> cMo_vec;
380  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
381  CHECK(cMo_vec.size() == nbTags);
382  return cMo_vec;
383  };
384  }
385 
386  SECTION("tag36_11")
387  {
389  "AprilTag/benchmark/640x480/tag36_11_640x480.png");
390  REQUIRE(vpIoTools::checkFilename(filename));
392  vpImageIo::read(I, filename);
393 
395  BENCHMARK("Benchmark Apriltag detection: tag36_11 640x480")
396  {
397  std::vector<vpHomogeneousMatrix> cMo_vec;
398  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
399  CHECK(cMo_vec.size() == nbTags);
400  return cMo_vec;
401  };
402  }
403 
404  SECTION("tag21_07")
405  {
407  "AprilTag/benchmark/640x480/tag21_07_640x480.png");
408  REQUIRE(vpIoTools::checkFilename(filename));
410  vpImageIo::read(I, filename);
411 
413  BENCHMARK("Benchmark Apriltag detection: tag21_07 640x480")
414  {
415  std::vector<vpHomogeneousMatrix> cMo_vec;
416  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
417  CHECK(cMo_vec.size() == nbTags);
418  return cMo_vec;
419  };
420  }
421 
422 #if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
423  SECTION("tag49_12")
424  {
426  "AprilTag/benchmark/640x480/tag49_12_640x480.png");
427  REQUIRE(vpIoTools::checkFilename(filename));
429  vpImageIo::read(I, filename);
430 
432  BENCHMARK("Benchmark Apriltag detection: tag49_12 640x480")
433  {
434  std::vector<vpHomogeneousMatrix> cMo_vec;
435  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
436  CHECK(cMo_vec.size() == nbTags);
437  return cMo_vec;
438  };
439  }
440 
441  SECTION("tag48_12")
442  {
444  "AprilTag/benchmark/640x480/tag48_12_640x480.png");
445  REQUIRE(vpIoTools::checkFilename(filename));
447  vpImageIo::read(I, filename);
448 
450  BENCHMARK("Benchmark Apriltag detection: tag48_12 640x480")
451  {
452  std::vector<vpHomogeneousMatrix> cMo_vec;
453  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
454  CHECK(cMo_vec.size() == nbTags);
455  return cMo_vec;
456  };
457  }
458 
459  SECTION("tag41_12")
460  {
462  "AprilTag/benchmark/640x480/tag41_12_640x480.png");
463  REQUIRE(vpIoTools::checkFilename(filename));
465  vpImageIo::read(I, filename);
466 
468  BENCHMARK("Benchmark Apriltag detection: tag41_12 640x480")
469  {
470  std::vector<vpHomogeneousMatrix> cMo_vec;
471  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
472  CHECK(cMo_vec.size() == nbTags);
473  return cMo_vec;
474  };
475  }
476 
477  SECTION("tag52_13")
478  {
480  "AprilTag/benchmark/640x480/tag52_13_640x480.png");
481  REQUIRE(vpIoTools::checkFilename(filename));
483  vpImageIo::read(I, filename);
484 
486  BENCHMARK("Benchmark Apriltag detection: tag52_13 640x480")
487  {
488  std::vector<vpHomogeneousMatrix> cMo_vec;
489  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
490  CHECK(cMo_vec.size() == nbTags);
491  return cMo_vec;
492  };
493  }
494 #endif
495 }
496 
497 int main(int argc, char *argv[])
498 {
499  Catch::Session session; // There must be exactly one instance
500 
501  bool runBenchmark = false;
502  // Build a new parser on top of Catch's
503  using namespace Catch::clara;
504  auto cli = session.cli() // Get Catch's composite command line parser
505  | Opt(runBenchmark) // bind variable to a new option, with a hint string
506  ["--benchmark"] // the option names it will respond to
507  ("run benchmark?"); // description string for the help output
508 
509  // Now pass the new composite back to Catch so it uses that
510  session.cli(cli);
511 
512  // Let Catch (using Clara) parse the command line
513  session.applyCommandLine(argc, argv);
514 
515  if (runBenchmark) {
516  int numFailed = session.run();
517 
518  // numFailed is clamped to 255 as some unices only use the lower 8 bits.
519  // This clamping has already been applied, so just return it here
520  // You can also do any post run clean-up here
521  return numFailed;
522  }
523 
524  return EXIT_SUCCESS;
525 }
526 #else
527 int main() { return EXIT_SUCCESS; }
528 #endif
Generic class defining intrinsic camera parameters.
@ TAG_CIRCLE21h7
AprilTag Circle21h7 pattern.
@ TAG_25h9
AprilTag 25h9 pattern.
@ TAG_CUSTOM48h12
AprilTag Custom48h12 pattern.
@ TAG_36h11
AprilTag 36h11 pattern (recommended)
@ TAG_STANDARD52h13
AprilTag Standard52h13 pattern.
@ TAG_16h5
AprilTag 16h5 pattern.
@ TAG_STANDARD41h12
AprilTag Standard41h12 pattern.
@ TAG_CIRCLE49h12
AprilTag Circle49h12 pattern.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:143
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1832
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:1213
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:2195