37#include <visp3/core/vpConfig.h>
39#if defined(VISP_HAVE_CATCH2)
41#include <catch_amalgamated.hpp>
43#include <visp3/core/vpIoTools.h>
44#include <visp3/detection/vpDetectorAprilTag.h>
45#include <visp3/io/vpImageIo.h>
47#ifdef ENABLE_VISP_NAMESPACE
51static int g_nb_threads = 1;
52static float g_quad_sigma = 0;
53static bool g_use_blur =
false;
55TEST_CASE(
"Benchmark Apriltag detection 1920x1080",
"[benchmark]")
57 const double tagSize = 0.25;
59 const size_t nbTags = 5;
64 "AprilTag/benchmark/1920x1080/tag16_05_1920x1080.png");
70 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
72 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
74 BENCHMARK(
"Benchmark Apriltag detection: tag16_05 1920x1080")
76 std::vector<vpHomogeneousMatrix> cMo_vec;
77 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
78 CHECK(cMo_vec.size() == nbTags);
82 apriltag_detector.setAprilTagQuadDecimate(2);
83 BENCHMARK(
"Benchmark Apriltag detection: tag16_05 1920x1080 decimate=2")
85 std::vector<vpHomogeneousMatrix> cMo_vec;
86 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
87 CHECK(cMo_vec.size() == nbTags);
91 apriltag_detector.setAprilTagQuadDecimate(3);
92 BENCHMARK(
"Benchmark Apriltag detection: tag16_05 1920x1080 decimate=3")
94 std::vector<vpHomogeneousMatrix> cMo_vec;
95 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
96 CHECK(cMo_vec.size() == nbTags);
104 "AprilTag/benchmark/1920x1080/tag25_09_1920x1080.png");
110 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
112 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
114 BENCHMARK(
"Benchmark Apriltag detection: tag25_09 1920x1080")
116 std::vector<vpHomogeneousMatrix> cMo_vec;
117 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
118 CHECK(cMo_vec.size() == nbTags);
122 apriltag_detector.setAprilTagQuadDecimate(2);
123 BENCHMARK(
"Benchmark Apriltag detection: tag25_09 1920x1080 decimate=2")
125 std::vector<vpHomogeneousMatrix> cMo_vec;
126 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
127 CHECK(cMo_vec.size() == nbTags);
131 apriltag_detector.setAprilTagQuadDecimate(3);
132 BENCHMARK(
"Benchmark Apriltag detection: tag25_09 1920x1080 decimate=3")
134 std::vector<vpHomogeneousMatrix> cMo_vec;
135 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
136 CHECK(cMo_vec.size() == nbTags);
144 "AprilTag/benchmark/1920x1080/tag36_11_1920x1080.png");
150 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
152 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
154 BENCHMARK(
"Benchmark Apriltag detection: tag36_11 1920x1080")
156 std::vector<vpHomogeneousMatrix> cMo_vec;
157 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
158 CHECK(cMo_vec.size() == nbTags);
162 apriltag_detector.setAprilTagQuadDecimate(2);
163 BENCHMARK(
"Benchmark Apriltag detection: tag36_11 1920x1080 decimate=2")
165 std::vector<vpHomogeneousMatrix> cMo_vec;
166 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
167 CHECK(cMo_vec.size() == nbTags);
171 apriltag_detector.setAprilTagQuadDecimate(3);
172 BENCHMARK(
"Benchmark Apriltag detection: tag36_11 1920x1080 decimate=3")
174 std::vector<vpHomogeneousMatrix> cMo_vec;
175 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
176 CHECK(cMo_vec.size() == nbTags);
184 "AprilTag/benchmark/1920x1080/tag21_07_1920x1080.png");
190 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
192 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
194 BENCHMARK(
"Benchmark Apriltag detection: tag21_07 1920x1080")
196 std::vector<vpHomogeneousMatrix> cMo_vec;
197 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
198 CHECK(cMo_vec.size() == nbTags);
202 apriltag_detector.setAprilTagQuadDecimate(2);
203 BENCHMARK(
"Benchmark Apriltag detection: tag21_07 1920x1080 decimate=2")
205 std::vector<vpHomogeneousMatrix> cMo_vec;
206 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
207 CHECK(cMo_vec.size() == nbTags);
211 apriltag_detector.setAprilTagQuadDecimate(3);
212 BENCHMARK(
"Benchmark Apriltag detection: tag21_07 1920x1080 decimate=3")
214 std::vector<vpHomogeneousMatrix> cMo_vec;
215 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
216 CHECK(cMo_vec.size() == nbTags);
221#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
225 "AprilTag/benchmark/1920x1080/tag49_12_1920x1080.png");
231 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
233 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
235 BENCHMARK(
"Benchmark Apriltag detection: tag49_12 1920x1080")
237 std::vector<vpHomogeneousMatrix> cMo_vec;
238 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
239 CHECK(cMo_vec.size() == nbTags);
243 apriltag_detector.setAprilTagQuadDecimate(2);
244 BENCHMARK(
"Benchmark Apriltag detection: tag49_12 1920x1080 decimate=2")
246 std::vector<vpHomogeneousMatrix> cMo_vec;
247 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
248 CHECK(cMo_vec.size() == nbTags);
252 apriltag_detector.setAprilTagQuadDecimate(3);
253 BENCHMARK(
"Benchmark Apriltag detection: tag49_12 1920x1080 decimate=3")
255 std::vector<vpHomogeneousMatrix> cMo_vec;
256 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
257 CHECK(cMo_vec.size() == nbTags);
265 "AprilTag/benchmark/1920x1080/tag48_12_1920x1080.png");
271 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
273 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
275 BENCHMARK(
"Benchmark Apriltag detection: tag48_12 1920x1080")
277 std::vector<vpHomogeneousMatrix> cMo_vec;
278 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
279 CHECK(cMo_vec.size() == nbTags);
283 apriltag_detector.setAprilTagQuadDecimate(2);
284 BENCHMARK(
"Benchmark Apriltag detection: tag48_12 1920x1080 decimate=2")
286 std::vector<vpHomogeneousMatrix> cMo_vec;
287 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
288 CHECK(cMo_vec.size() == nbTags);
292 apriltag_detector.setAprilTagQuadDecimate(3);
293 BENCHMARK(
"Benchmark Apriltag detection: tag48_12 1920x1080 decimate=3")
295 std::vector<vpHomogeneousMatrix> cMo_vec;
296 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
297 CHECK(cMo_vec.size() == nbTags);
305 "AprilTag/benchmark/1920x1080/tag41_12_1920x1080.png");
311 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
313 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
315 BENCHMARK(
"Benchmark Apriltag detection: tag41_12 1920x1080")
317 std::vector<vpHomogeneousMatrix> cMo_vec;
318 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
319 CHECK(cMo_vec.size() == nbTags);
323 apriltag_detector.setAprilTagQuadDecimate(2);
324 BENCHMARK(
"Benchmark Apriltag detection: tag41_12 1920x1080 decimate=2")
326 std::vector<vpHomogeneousMatrix> cMo_vec;
327 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
328 CHECK(cMo_vec.size() == nbTags);
332 apriltag_detector.setAprilTagQuadDecimate(3);
333 BENCHMARK(
"Benchmark Apriltag detection: tag41_12 1920x1080 decimate=3")
335 std::vector<vpHomogeneousMatrix> cMo_vec;
336 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
337 CHECK(cMo_vec.size() == nbTags);
345 "AprilTag/benchmark/1920x1080/tag52_13_1920x1080.png");
351 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
353 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
355 BENCHMARK(
"Benchmark Apriltag detection: tag52_13 1920x1080")
357 std::vector<vpHomogeneousMatrix> cMo_vec;
358 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
359 CHECK(cMo_vec.size() == nbTags);
363 apriltag_detector.setAprilTagQuadDecimate(2);
364 BENCHMARK(
"Benchmark Apriltag detection: tag52_13 1920x1080 decimate=2")
366 std::vector<vpHomogeneousMatrix> cMo_vec;
367 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
368 CHECK(cMo_vec.size() == nbTags);
372 apriltag_detector.setAprilTagQuadDecimate(3);
373 BENCHMARK(
"Benchmark Apriltag detection: tag52_13 1920x1080 decimate=3")
375 std::vector<vpHomogeneousMatrix> cMo_vec;
376 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
377 CHECK(cMo_vec.size() == nbTags);
384TEST_CASE(
"Benchmark Apriltag detection 640x480",
"[benchmark]")
386 const double tagSize = 0.25;
388 const size_t nbTags = 5;
393 "AprilTag/benchmark/640x480/tag16_05_640x480.png");
399 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
401 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
403 BENCHMARK(
"Benchmark Apriltag detection: tag16_05 640x480")
405 std::vector<vpHomogeneousMatrix> cMo_vec;
406 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
407 CHECK(cMo_vec.size() == nbTags);
415 "AprilTag/benchmark/640x480/tag25_09_640x480.png");
421 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
423 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
425 BENCHMARK(
"Benchmark Apriltag detection: tag25_09 640x480")
427 std::vector<vpHomogeneousMatrix> cMo_vec;
428 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
429 CHECK(cMo_vec.size() == nbTags);
437 "AprilTag/benchmark/640x480/tag36_11_640x480.png");
443 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
445 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
447 BENCHMARK(
"Benchmark Apriltag detection: tag36_11 640x480")
449 std::vector<vpHomogeneousMatrix> cMo_vec;
450 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
451 CHECK(cMo_vec.size() == nbTags);
459 "AprilTag/benchmark/640x480/tag21_07_640x480.png");
465 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
467 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
469 BENCHMARK(
"Benchmark Apriltag detection: tag21_07 640x480")
471 std::vector<vpHomogeneousMatrix> cMo_vec;
472 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
473 CHECK(cMo_vec.size() == nbTags);
478#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
482 "AprilTag/benchmark/640x480/tag49_12_640x480.png");
488 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
490 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
492 BENCHMARK(
"Benchmark Apriltag detection: tag49_12 640x480")
494 std::vector<vpHomogeneousMatrix> cMo_vec;
495 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
496 CHECK(cMo_vec.size() == nbTags);
504 "AprilTag/benchmark/640x480/tag48_12_640x480.png");
510 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
512 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
514 BENCHMARK(
"Benchmark Apriltag detection: tag48_12 640x480")
516 std::vector<vpHomogeneousMatrix> cMo_vec;
517 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
518 CHECK(cMo_vec.size() == nbTags);
526 "AprilTag/benchmark/640x480/tag41_12_640x480.png");
532 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
534 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
536 BENCHMARK(
"Benchmark Apriltag detection: tag41_12 640x480")
538 std::vector<vpHomogeneousMatrix> cMo_vec;
539 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
540 CHECK(cMo_vec.size() == nbTags);
548 "AprilTag/benchmark/640x480/tag52_13_640x480.png");
554 apriltag_detector.setAprilTagNbThreads(g_nb_threads);
556 apriltag_detector.setAprilTagQuadSigma(g_quad_sigma);
558 BENCHMARK(
"Benchmark Apriltag detection: tag52_13 640x480")
560 std::vector<vpHomogeneousMatrix> cMo_vec;
561 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
562 CHECK(cMo_vec.size() == nbTags);
569int main(
int argc,
char *argv[])
571 Catch::Session session;
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.");
580 session.applyCommandLine(argc, argv);
583 std::cout <<
"Use " << g_nb_threads <<
" threads for AprilTag detection." << std::endl;
584 if (std::fabs(g_quad_sigma) > 1e-9) {
586 std::cout <<
"Use Gaussian blur with " << g_quad_sigma <<
" standard deviation." << std::endl;
588 int numFailed = session.run();
596int main() {
return EXIT_SUCCESS; }
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.