Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
perfApriltagDetection.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Apriltag detection performance test.
32  */
33 
37 #include <visp3/core/vpConfig.h>
38 
39 #if defined(VISP_HAVE_CATCH2)
40 
41 #include <catch_amalgamated.hpp>
42 
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/detection/vpDetectorAprilTag.h>
45 #include <visp3/io/vpImageIo.h>
46 
47 #ifdef ENABLE_VISP_NAMESPACE
48 using namespace VISP_NAMESPACE_NAME;
49 #endif
50 
51 TEST_CASE("Benchmark Apriltag detection 1920x1080", "[benchmark]")
52 {
53  const double tagSize = 0.25;
54  const vpCameraParameters cam(2100, 2100, 960, 540);
55  const size_t nbTags = 5;
56 
57  SECTION("tag16_05")
58  {
60  "AprilTag/benchmark/1920x1080/tag16_05_1920x1080.png");
61  REQUIRE(vpIoTools::checkFilename(filename));
63  vpImageIo::read(I, filename);
64 
66  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080")
67  {
68  std::vector<vpHomogeneousMatrix> cMo_vec;
69  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
70  CHECK(cMo_vec.size() == nbTags);
71  return cMo_vec;
72  };
73 
74  apriltag_detector.setAprilTagQuadDecimate(2);
75  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=2")
76  {
77  std::vector<vpHomogeneousMatrix> cMo_vec;
78  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
79  CHECK(cMo_vec.size() == nbTags);
80  return cMo_vec;
81  };
82 
83  apriltag_detector.setAprilTagQuadDecimate(3);
84  BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=3")
85  {
86  std::vector<vpHomogeneousMatrix> cMo_vec;
87  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
88  CHECK(cMo_vec.size() == nbTags);
89  return cMo_vec;
90  };
91  }
92 
93  SECTION("tag25_09")
94  {
96  "AprilTag/benchmark/1920x1080/tag25_09_1920x1080.png");
97  REQUIRE(vpIoTools::checkFilename(filename));
99  vpImageIo::read(I, filename);
100 
102  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080")
103  {
104  std::vector<vpHomogeneousMatrix> cMo_vec;
105  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
106  CHECK(cMo_vec.size() == nbTags);
107  return cMo_vec;
108  };
109 
110  apriltag_detector.setAprilTagQuadDecimate(2);
111  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=2")
112  {
113  std::vector<vpHomogeneousMatrix> cMo_vec;
114  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
115  CHECK(cMo_vec.size() == nbTags);
116  return cMo_vec;
117  };
118 
119  apriltag_detector.setAprilTagQuadDecimate(3);
120  BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=3")
121  {
122  std::vector<vpHomogeneousMatrix> cMo_vec;
123  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
124  CHECK(cMo_vec.size() == nbTags);
125  return cMo_vec;
126  };
127  }
128 
129  SECTION("tag36_11")
130  {
132  "AprilTag/benchmark/1920x1080/tag36_11_1920x1080.png");
133  REQUIRE(vpIoTools::checkFilename(filename));
135  vpImageIo::read(I, filename);
136 
138  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080")
139  {
140  std::vector<vpHomogeneousMatrix> cMo_vec;
141  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
142  CHECK(cMo_vec.size() == nbTags);
143  return cMo_vec;
144  };
145 
146  apriltag_detector.setAprilTagQuadDecimate(2);
147  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=2")
148  {
149  std::vector<vpHomogeneousMatrix> cMo_vec;
150  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
151  CHECK(cMo_vec.size() == nbTags);
152  return cMo_vec;
153  };
154 
155  apriltag_detector.setAprilTagQuadDecimate(3);
156  BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=3")
157  {
158  std::vector<vpHomogeneousMatrix> cMo_vec;
159  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
160  CHECK(cMo_vec.size() == nbTags);
161  return cMo_vec;
162  };
163  }
164 
165  SECTION("tag21_07")
166  {
168  "AprilTag/benchmark/1920x1080/tag21_07_1920x1080.png");
169  REQUIRE(vpIoTools::checkFilename(filename));
171  vpImageIo::read(I, filename);
172 
174  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080")
175  {
176  std::vector<vpHomogeneousMatrix> cMo_vec;
177  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
178  CHECK(cMo_vec.size() == nbTags);
179  return cMo_vec;
180  };
181 
182  apriltag_detector.setAprilTagQuadDecimate(2);
183  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=2")
184  {
185  std::vector<vpHomogeneousMatrix> cMo_vec;
186  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
187  CHECK(cMo_vec.size() == nbTags);
188  return cMo_vec;
189  };
190 
191  apriltag_detector.setAprilTagQuadDecimate(3);
192  BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=3")
193  {
194  std::vector<vpHomogeneousMatrix> cMo_vec;
195  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
196  CHECK(cMo_vec.size() == nbTags);
197  return cMo_vec;
198  };
199  }
200 
201 #if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
202  SECTION("tag49_12")
203  {
205  "AprilTag/benchmark/1920x1080/tag49_12_1920x1080.png");
206  REQUIRE(vpIoTools::checkFilename(filename));
208  vpImageIo::read(I, filename);
209 
211  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080")
212  {
213  std::vector<vpHomogeneousMatrix> cMo_vec;
214  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
215  CHECK(cMo_vec.size() == nbTags);
216  return cMo_vec;
217  };
218 
219  apriltag_detector.setAprilTagQuadDecimate(2);
220  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=2")
221  {
222  std::vector<vpHomogeneousMatrix> cMo_vec;
223  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
224  CHECK(cMo_vec.size() == nbTags);
225  return cMo_vec;
226  };
227 
228  apriltag_detector.setAprilTagQuadDecimate(3);
229  BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=3")
230  {
231  std::vector<vpHomogeneousMatrix> cMo_vec;
232  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
233  CHECK(cMo_vec.size() == nbTags);
234  return cMo_vec;
235  };
236  }
237 
238  SECTION("tag48_12")
239  {
241  "AprilTag/benchmark/1920x1080/tag48_12_1920x1080.png");
242  REQUIRE(vpIoTools::checkFilename(filename));
244  vpImageIo::read(I, filename);
245 
247  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080")
248  {
249  std::vector<vpHomogeneousMatrix> cMo_vec;
250  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
251  CHECK(cMo_vec.size() == nbTags);
252  return cMo_vec;
253  };
254 
255  apriltag_detector.setAprilTagQuadDecimate(2);
256  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=2")
257  {
258  std::vector<vpHomogeneousMatrix> cMo_vec;
259  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
260  CHECK(cMo_vec.size() == nbTags);
261  return cMo_vec;
262  };
263 
264  apriltag_detector.setAprilTagQuadDecimate(3);
265  BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=3")
266  {
267  std::vector<vpHomogeneousMatrix> cMo_vec;
268  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
269  CHECK(cMo_vec.size() == nbTags);
270  return cMo_vec;
271  };
272  }
273 
274  SECTION("tag41_12")
275  {
277  "AprilTag/benchmark/1920x1080/tag41_12_1920x1080.png");
278  REQUIRE(vpIoTools::checkFilename(filename));
280  vpImageIo::read(I, filename);
281 
283  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080")
284  {
285  std::vector<vpHomogeneousMatrix> cMo_vec;
286  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
287  CHECK(cMo_vec.size() == nbTags);
288  return cMo_vec;
289  };
290 
291  apriltag_detector.setAprilTagQuadDecimate(2);
292  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=2")
293  {
294  std::vector<vpHomogeneousMatrix> cMo_vec;
295  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
296  CHECK(cMo_vec.size() == nbTags);
297  return cMo_vec;
298  };
299 
300  apriltag_detector.setAprilTagQuadDecimate(3);
301  BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=3")
302  {
303  std::vector<vpHomogeneousMatrix> cMo_vec;
304  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
305  CHECK(cMo_vec.size() == nbTags);
306  return cMo_vec;
307  };
308  }
309 
310  SECTION("tag52_13")
311  {
313  "AprilTag/benchmark/1920x1080/tag52_13_1920x1080.png");
314  REQUIRE(vpIoTools::checkFilename(filename));
316  vpImageIo::read(I, filename);
317 
319  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080")
320  {
321  std::vector<vpHomogeneousMatrix> cMo_vec;
322  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
323  CHECK(cMo_vec.size() == nbTags);
324  return cMo_vec;
325  };
326 
327  apriltag_detector.setAprilTagQuadDecimate(2);
328  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=2")
329  {
330  std::vector<vpHomogeneousMatrix> cMo_vec;
331  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
332  CHECK(cMo_vec.size() == nbTags);
333  return cMo_vec;
334  };
335 
336  apriltag_detector.setAprilTagQuadDecimate(3);
337  BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=3")
338  {
339  std::vector<vpHomogeneousMatrix> cMo_vec;
340  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
341  CHECK(cMo_vec.size() == nbTags);
342  return cMo_vec;
343  };
344  }
345 #endif
346 }
347 
348 TEST_CASE("Benchmark Apriltag detection 640x480", "[benchmark]")
349 {
350  const double tagSize = 0.25;
351  const vpCameraParameters cam(700, 700, 320, 240);
352  const size_t nbTags = 5;
353 
354  SECTION("tag16_05")
355  {
357  "AprilTag/benchmark/640x480/tag16_05_640x480.png");
358  REQUIRE(vpIoTools::checkFilename(filename));
360  vpImageIo::read(I, filename);
361 
363  BENCHMARK("Benchmark Apriltag detection: tag16_05 640x480")
364  {
365  std::vector<vpHomogeneousMatrix> cMo_vec;
366  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
367  CHECK(cMo_vec.size() == nbTags);
368  return cMo_vec;
369  };
370  }
371 
372  SECTION("tag25_09")
373  {
375  "AprilTag/benchmark/640x480/tag25_09_640x480.png");
376  REQUIRE(vpIoTools::checkFilename(filename));
378  vpImageIo::read(I, filename);
379 
381  BENCHMARK("Benchmark Apriltag detection: tag25_09 640x480")
382  {
383  std::vector<vpHomogeneousMatrix> cMo_vec;
384  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
385  CHECK(cMo_vec.size() == nbTags);
386  return cMo_vec;
387  };
388  }
389 
390  SECTION("tag36_11")
391  {
393  "AprilTag/benchmark/640x480/tag36_11_640x480.png");
394  REQUIRE(vpIoTools::checkFilename(filename));
396  vpImageIo::read(I, filename);
397 
399  BENCHMARK("Benchmark Apriltag detection: tag36_11 640x480")
400  {
401  std::vector<vpHomogeneousMatrix> cMo_vec;
402  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
403  CHECK(cMo_vec.size() == nbTags);
404  return cMo_vec;
405  };
406  }
407 
408  SECTION("tag21_07")
409  {
411  "AprilTag/benchmark/640x480/tag21_07_640x480.png");
412  REQUIRE(vpIoTools::checkFilename(filename));
414  vpImageIo::read(I, filename);
415 
417  BENCHMARK("Benchmark Apriltag detection: tag21_07 640x480")
418  {
419  std::vector<vpHomogeneousMatrix> cMo_vec;
420  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
421  CHECK(cMo_vec.size() == nbTags);
422  return cMo_vec;
423  };
424  }
425 
426 #if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
427  SECTION("tag49_12")
428  {
430  "AprilTag/benchmark/640x480/tag49_12_640x480.png");
431  REQUIRE(vpIoTools::checkFilename(filename));
433  vpImageIo::read(I, filename);
434 
436  BENCHMARK("Benchmark Apriltag detection: tag49_12 640x480")
437  {
438  std::vector<vpHomogeneousMatrix> cMo_vec;
439  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
440  CHECK(cMo_vec.size() == nbTags);
441  return cMo_vec;
442  };
443  }
444 
445  SECTION("tag48_12")
446  {
448  "AprilTag/benchmark/640x480/tag48_12_640x480.png");
449  REQUIRE(vpIoTools::checkFilename(filename));
451  vpImageIo::read(I, filename);
452 
454  BENCHMARK("Benchmark Apriltag detection: tag48_12 640x480")
455  {
456  std::vector<vpHomogeneousMatrix> cMo_vec;
457  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
458  CHECK(cMo_vec.size() == nbTags);
459  return cMo_vec;
460  };
461  }
462 
463  SECTION("tag41_12")
464  {
466  "AprilTag/benchmark/640x480/tag41_12_640x480.png");
467  REQUIRE(vpIoTools::checkFilename(filename));
469  vpImageIo::read(I, filename);
470 
472  BENCHMARK("Benchmark Apriltag detection: tag41_12 640x480")
473  {
474  std::vector<vpHomogeneousMatrix> cMo_vec;
475  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
476  CHECK(cMo_vec.size() == nbTags);
477  return cMo_vec;
478  };
479  }
480 
481  SECTION("tag52_13")
482  {
484  "AprilTag/benchmark/640x480/tag52_13_640x480.png");
485  REQUIRE(vpIoTools::checkFilename(filename));
487  vpImageIo::read(I, filename);
488 
490  BENCHMARK("Benchmark Apriltag detection: tag52_13 640x480")
491  {
492  std::vector<vpHomogeneousMatrix> cMo_vec;
493  apriltag_detector.detect(I, tagSize, cam, cMo_vec);
494  CHECK(cMo_vec.size() == nbTags);
495  return cMo_vec;
496  };
497  }
498 #endif
499 }
500 
501 int main(int argc, char *argv[])
502 {
503  Catch::Session session;
504 
505  bool runBenchmark = false;
506  auto cli = session.cli()
507  | Catch::Clara::Opt(runBenchmark)["--benchmark"]("run benchmark?");
508 
509  session.cli(cli);
510  session.applyCommandLine(argc, argv);
511 
512  if (runBenchmark) {
513  int numFailed = session.run();
514  return numFailed;
515  }
516 
517  return EXIT_SUCCESS;
518 }
519 
520 #else
521 int main() { return EXIT_SUCCESS; }
522 #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:147
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1053
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:786
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1427