Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
48using namespace VISP_NAMESPACE_NAME;
49#endif
50
51static int g_nb_threads = 1;
52static float g_quad_sigma = 0;
53static bool g_use_blur = false;
54
55TEST_CASE("Benchmark Apriltag detection 1920x1080", "[benchmark]")
56{
57 const double tagSize = 0.25;
58 const vpCameraParameters cam(2100, 2100, 960, 540);
59 const size_t nbTags = 5;
60
61 SECTION("tag16_05")
62 {
64 "AprilTag/benchmark/1920x1080/tag16_05_1920x1080.png");
65 REQUIRE(vpIoTools::checkFilename(filename));
67 vpImageIo::read(I, filename);
68
70 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
71 if (g_use_blur) {
72 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
73 }
74 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080")
75 {
76 std::vector<vpHomogeneousMatrix> cMo_vec;
77 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
78 CHECK(cMo_vec.size() == nbTags);
79 return cMo_vec;
80 };
81
82 apriltag_detector.setAprilTagQuadDecimate(2);
83 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=2")
84 {
85 std::vector<vpHomogeneousMatrix> cMo_vec;
86 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
87 CHECK(cMo_vec.size() == nbTags);
88 return cMo_vec;
89 };
90
91 apriltag_detector.setAprilTagQuadDecimate(3);
92 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=3")
93 {
94 std::vector<vpHomogeneousMatrix> cMo_vec;
95 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
96 CHECK(cMo_vec.size() == nbTags);
97 return cMo_vec;
98 };
99 }
100
101 SECTION("tag25_09")
102 {
104 "AprilTag/benchmark/1920x1080/tag25_09_1920x1080.png");
105 REQUIRE(vpIoTools::checkFilename(filename));
107 vpImageIo::read(I, filename);
108
110 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
111 if (g_use_blur) {
112 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
113 }
114 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080")
115 {
116 std::vector<vpHomogeneousMatrix> cMo_vec;
117 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
118 CHECK(cMo_vec.size() == nbTags);
119 return cMo_vec;
120 };
121
122 apriltag_detector.setAprilTagQuadDecimate(2);
123 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=2")
124 {
125 std::vector<vpHomogeneousMatrix> cMo_vec;
126 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
127 CHECK(cMo_vec.size() == nbTags);
128 return cMo_vec;
129 };
130
131 apriltag_detector.setAprilTagQuadDecimate(3);
132 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=3")
133 {
134 std::vector<vpHomogeneousMatrix> cMo_vec;
135 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
136 CHECK(cMo_vec.size() == nbTags);
137 return cMo_vec;
138 };
139 }
140
141 SECTION("tag36_11")
142 {
144 "AprilTag/benchmark/1920x1080/tag36_11_1920x1080.png");
145 REQUIRE(vpIoTools::checkFilename(filename));
147 vpImageIo::read(I, filename);
148
150 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
151 if (g_use_blur) {
152 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
153 }
154 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080")
155 {
156 std::vector<vpHomogeneousMatrix> cMo_vec;
157 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
158 CHECK(cMo_vec.size() == nbTags);
159 return cMo_vec;
160 };
161
162 apriltag_detector.setAprilTagQuadDecimate(2);
163 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=2")
164 {
165 std::vector<vpHomogeneousMatrix> cMo_vec;
166 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
167 CHECK(cMo_vec.size() == nbTags);
168 return cMo_vec;
169 };
170
171 apriltag_detector.setAprilTagQuadDecimate(3);
172 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=3")
173 {
174 std::vector<vpHomogeneousMatrix> cMo_vec;
175 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
176 CHECK(cMo_vec.size() == nbTags);
177 return cMo_vec;
178 };
179 }
180
181 SECTION("tag21_07")
182 {
184 "AprilTag/benchmark/1920x1080/tag21_07_1920x1080.png");
185 REQUIRE(vpIoTools::checkFilename(filename));
187 vpImageIo::read(I, filename);
188
190 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
191 if (g_use_blur) {
192 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
193 }
194 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080")
195 {
196 std::vector<vpHomogeneousMatrix> cMo_vec;
197 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
198 CHECK(cMo_vec.size() == nbTags);
199 return cMo_vec;
200 };
201
202 apriltag_detector.setAprilTagQuadDecimate(2);
203 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=2")
204 {
205 std::vector<vpHomogeneousMatrix> cMo_vec;
206 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
207 CHECK(cMo_vec.size() == nbTags);
208 return cMo_vec;
209 };
210
211 apriltag_detector.setAprilTagQuadDecimate(3);
212 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=3")
213 {
214 std::vector<vpHomogeneousMatrix> cMo_vec;
215 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
216 CHECK(cMo_vec.size() == nbTags);
217 return cMo_vec;
218 };
219 }
220
221#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
222 SECTION("tag49_12")
223 {
225 "AprilTag/benchmark/1920x1080/tag49_12_1920x1080.png");
226 REQUIRE(vpIoTools::checkFilename(filename));
228 vpImageIo::read(I, filename);
229
231 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
232 if (g_use_blur) {
233 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
234 }
235 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080")
236 {
237 std::vector<vpHomogeneousMatrix> cMo_vec;
238 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
239 CHECK(cMo_vec.size() == nbTags);
240 return cMo_vec;
241 };
242
243 apriltag_detector.setAprilTagQuadDecimate(2);
244 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=2")
245 {
246 std::vector<vpHomogeneousMatrix> cMo_vec;
247 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
248 CHECK(cMo_vec.size() == nbTags);
249 return cMo_vec;
250 };
251
252 apriltag_detector.setAprilTagQuadDecimate(3);
253 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=3")
254 {
255 std::vector<vpHomogeneousMatrix> cMo_vec;
256 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
257 CHECK(cMo_vec.size() == nbTags);
258 return cMo_vec;
259 };
260 }
261
262 SECTION("tag48_12")
263 {
265 "AprilTag/benchmark/1920x1080/tag48_12_1920x1080.png");
266 REQUIRE(vpIoTools::checkFilename(filename));
268 vpImageIo::read(I, filename);
269
271 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
272 if (g_use_blur) {
273 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
274 }
275 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080")
276 {
277 std::vector<vpHomogeneousMatrix> cMo_vec;
278 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
279 CHECK(cMo_vec.size() == nbTags);
280 return cMo_vec;
281 };
282
283 apriltag_detector.setAprilTagQuadDecimate(2);
284 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=2")
285 {
286 std::vector<vpHomogeneousMatrix> cMo_vec;
287 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
288 CHECK(cMo_vec.size() == nbTags);
289 return cMo_vec;
290 };
291
292 apriltag_detector.setAprilTagQuadDecimate(3);
293 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=3")
294 {
295 std::vector<vpHomogeneousMatrix> cMo_vec;
296 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
297 CHECK(cMo_vec.size() == nbTags);
298 return cMo_vec;
299 };
300 }
301
302 SECTION("tag41_12")
303 {
305 "AprilTag/benchmark/1920x1080/tag41_12_1920x1080.png");
306 REQUIRE(vpIoTools::checkFilename(filename));
308 vpImageIo::read(I, filename);
309
311 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
312 if (g_use_blur) {
313 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
314 }
315 BENCHMARK("Benchmark Apriltag detection: tag41_12 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: tag41_12 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: tag41_12 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
342 SECTION("tag52_13")
343 {
345 "AprilTag/benchmark/1920x1080/tag52_13_1920x1080.png");
346 REQUIRE(vpIoTools::checkFilename(filename));
348 vpImageIo::read(I, filename);
349
351 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
352 if (g_use_blur) {
353 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
354 }
355 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080")
356 {
357 std::vector<vpHomogeneousMatrix> cMo_vec;
358 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
359 CHECK(cMo_vec.size() == nbTags);
360 return cMo_vec;
361 };
362
363 apriltag_detector.setAprilTagQuadDecimate(2);
364 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=2")
365 {
366 std::vector<vpHomogeneousMatrix> cMo_vec;
367 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
368 CHECK(cMo_vec.size() == nbTags);
369 return cMo_vec;
370 };
371
372 apriltag_detector.setAprilTagQuadDecimate(3);
373 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=3")
374 {
375 std::vector<vpHomogeneousMatrix> cMo_vec;
376 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
377 CHECK(cMo_vec.size() == nbTags);
378 return cMo_vec;
379 };
380 }
381#endif
382}
383
384TEST_CASE("Benchmark Apriltag detection 640x480", "[benchmark]")
385{
386 const double tagSize = 0.25;
387 const vpCameraParameters cam(700, 700, 320, 240);
388 const size_t nbTags = 5;
389
390 SECTION("tag16_05")
391 {
393 "AprilTag/benchmark/640x480/tag16_05_640x480.png");
394 REQUIRE(vpIoTools::checkFilename(filename));
396 vpImageIo::read(I, filename);
397
399 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
400 if (g_use_blur) {
401 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
402 }
403 BENCHMARK("Benchmark Apriltag detection: tag16_05 640x480")
404 {
405 std::vector<vpHomogeneousMatrix> cMo_vec;
406 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
407 CHECK(cMo_vec.size() == nbTags);
408 return cMo_vec;
409 };
410 }
411
412 SECTION("tag25_09")
413 {
415 "AprilTag/benchmark/640x480/tag25_09_640x480.png");
416 REQUIRE(vpIoTools::checkFilename(filename));
418 vpImageIo::read(I, filename);
419
421 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
422 if (g_use_blur) {
423 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
424 }
425 BENCHMARK("Benchmark Apriltag detection: tag25_09 640x480")
426 {
427 std::vector<vpHomogeneousMatrix> cMo_vec;
428 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
429 CHECK(cMo_vec.size() == nbTags);
430 return cMo_vec;
431 };
432 }
433
434 SECTION("tag36_11")
435 {
437 "AprilTag/benchmark/640x480/tag36_11_640x480.png");
438 REQUIRE(vpIoTools::checkFilename(filename));
440 vpImageIo::read(I, filename);
441
443 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
444 if (g_use_blur) {
445 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
446 }
447 BENCHMARK("Benchmark Apriltag detection: tag36_11 640x480")
448 {
449 std::vector<vpHomogeneousMatrix> cMo_vec;
450 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
451 CHECK(cMo_vec.size() == nbTags);
452 return cMo_vec;
453 };
454 }
455
456 SECTION("tag21_07")
457 {
459 "AprilTag/benchmark/640x480/tag21_07_640x480.png");
460 REQUIRE(vpIoTools::checkFilename(filename));
462 vpImageIo::read(I, filename);
463
465 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
466 if (g_use_blur) {
467 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
468 }
469 BENCHMARK("Benchmark Apriltag detection: tag21_07 640x480")
470 {
471 std::vector<vpHomogeneousMatrix> cMo_vec;
472 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
473 CHECK(cMo_vec.size() == nbTags);
474 return cMo_vec;
475 };
476 }
477
478#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
479 SECTION("tag49_12")
480 {
482 "AprilTag/benchmark/640x480/tag49_12_640x480.png");
483 REQUIRE(vpIoTools::checkFilename(filename));
485 vpImageIo::read(I, filename);
486
488 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
489 if (g_use_blur) {
490 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
491 }
492 BENCHMARK("Benchmark Apriltag detection: tag49_12 640x480")
493 {
494 std::vector<vpHomogeneousMatrix> cMo_vec;
495 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
496 CHECK(cMo_vec.size() == nbTags);
497 return cMo_vec;
498 };
499 }
500
501 SECTION("tag48_12")
502 {
504 "AprilTag/benchmark/640x480/tag48_12_640x480.png");
505 REQUIRE(vpIoTools::checkFilename(filename));
507 vpImageIo::read(I, filename);
508
510 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
511 if (g_use_blur) {
512 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
513 }
514 BENCHMARK("Benchmark Apriltag detection: tag48_12 640x480")
515 {
516 std::vector<vpHomogeneousMatrix> cMo_vec;
517 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
518 CHECK(cMo_vec.size() == nbTags);
519 return cMo_vec;
520 };
521 }
522
523 SECTION("tag41_12")
524 {
526 "AprilTag/benchmark/640x480/tag41_12_640x480.png");
527 REQUIRE(vpIoTools::checkFilename(filename));
529 vpImageIo::read(I, filename);
530
532 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
533 if (g_use_blur) {
534 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
535 }
536 BENCHMARK("Benchmark Apriltag detection: tag41_12 640x480")
537 {
538 std::vector<vpHomogeneousMatrix> cMo_vec;
539 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
540 CHECK(cMo_vec.size() == nbTags);
541 return cMo_vec;
542 };
543 }
544
545 SECTION("tag52_13")
546 {
548 "AprilTag/benchmark/640x480/tag52_13_640x480.png");
549 REQUIRE(vpIoTools::checkFilename(filename));
551 vpImageIo::read(I, filename);
552
554 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
555 if (g_use_blur) {
556 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
557 }
558 BENCHMARK("Benchmark Apriltag detection: tag52_13 640x480")
559 {
560 std::vector<vpHomogeneousMatrix> cMo_vec;
561 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
562 CHECK(cMo_vec.size() == nbTags);
563 return cMo_vec;
564 };
565 }
566#endif
567}
568
569int main(int argc, char *argv[])
570{
571 Catch::Session session;
572
573 bool runBenchmark = false;
574 auto cli = session.cli()
575 | Catch::Clara::Opt(runBenchmark)["--benchmark"]("Actually run the AprilTag detection benchmark.")
576 | Catch::Clara::Opt(g_nb_threads, "g_nb_threads")["--nThreads"]("Number of threads for AprilTag detection.")
577 | Catch::Clara::Opt(g_quad_sigma, "g_quad_sigma")["--blur"]("Standard deviation for the Gaussian blur operation.");
578
579 session.cli(cli);
580 session.applyCommandLine(argc, argv);
581
582 if (runBenchmark) {
583 std::cout << "Use " << g_nb_threads << " threads for AprilTag detection." << std::endl;
584 if (std::fabs(g_quad_sigma) > 1e-9) {
585 g_use_blur = true;
586 std::cout << "Use Gaussian blur with " << g_quad_sigma << " standard deviation." << std::endl;
587 }
588 int numFailed = session.run();
589 return numFailed;
590 }
591
592 return EXIT_SUCCESS;
593}
594
595#else
596int main() { return EXIT_SUCCESS; }
597#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 of the vpImage class member functions.
Definition vpImage.h:131
static std::string getViSPImagesDataPath()
static bool checkFilename(const std::string &filename)
static std::string createFilePath(const std::string &parent, const std::string &child)