Visual Servoing Platform version 3.5.0
perfApriltagDetection.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 http://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
47TEST_CASE("Benchmark Apriltag detection 1920x1080", "[benchmark]") {
48 const double tagSize = 0.25;
49 const vpCameraParameters cam(2100, 2100, 960, 540);
50 const size_t nbTags = 5;
51
52 SECTION("tag16_05")
53 {
55 "AprilTag/benchmark/1920x1080/tag16_05_1920x1080.png");
56 REQUIRE(vpIoTools::checkFilename(filename));
58 vpImageIo::read(I, filename);
59
61 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080") {
62 std::vector<vpHomogeneousMatrix> cMo_vec;
63 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
64 CHECK(cMo_vec.size() == nbTags);
65 return cMo_vec;
66 };
67
68 apriltag_detector.setAprilTagQuadDecimate(2);
69 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=2") {
70 std::vector<vpHomogeneousMatrix> cMo_vec;
71 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
72 CHECK(cMo_vec.size() == nbTags);
73 return cMo_vec;
74 };
75
76 apriltag_detector.setAprilTagQuadDecimate(3);
77 BENCHMARK("Benchmark Apriltag detection: tag16_05 1920x1080 decimate=3") {
78 std::vector<vpHomogeneousMatrix> cMo_vec;
79 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
80 CHECK(cMo_vec.size() == nbTags);
81 return cMo_vec;
82 };
83 }
84
85 SECTION("tag25_09")
86 {
88 "AprilTag/benchmark/1920x1080/tag25_09_1920x1080.png");
89 REQUIRE(vpIoTools::checkFilename(filename));
91 vpImageIo::read(I, filename);
92
94 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080") {
95 std::vector<vpHomogeneousMatrix> cMo_vec;
96 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
97 CHECK(cMo_vec.size() == nbTags);
98 return cMo_vec;
99 };
100
101 apriltag_detector.setAprilTagQuadDecimate(2);
102 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=2") {
103 std::vector<vpHomogeneousMatrix> cMo_vec;
104 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
105 CHECK(cMo_vec.size() == nbTags);
106 return cMo_vec;
107 };
108
109 apriltag_detector.setAprilTagQuadDecimate(3);
110 BENCHMARK("Benchmark Apriltag detection: tag25_09 1920x1080 decimate=3") {
111 std::vector<vpHomogeneousMatrix> cMo_vec;
112 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
113 CHECK(cMo_vec.size() == nbTags);
114 return cMo_vec;
115 };
116 }
117
118 SECTION("tag36_11")
119 {
121 "AprilTag/benchmark/1920x1080/tag36_11_1920x1080.png");
122 REQUIRE(vpIoTools::checkFilename(filename));
124 vpImageIo::read(I, filename);
125
127 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080") {
128 std::vector<vpHomogeneousMatrix> cMo_vec;
129 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
130 CHECK(cMo_vec.size() == nbTags);
131 return cMo_vec;
132 };
133
134 apriltag_detector.setAprilTagQuadDecimate(2);
135 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=2") {
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(3);
143 BENCHMARK("Benchmark Apriltag detection: tag36_11 1920x1080 decimate=3") {
144 std::vector<vpHomogeneousMatrix> cMo_vec;
145 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
146 CHECK(cMo_vec.size() == nbTags);
147 return cMo_vec;
148 };
149 }
150
151 SECTION("tag21_07")
152 {
154 "AprilTag/benchmark/1920x1080/tag21_07_1920x1080.png");
155 REQUIRE(vpIoTools::checkFilename(filename));
157 vpImageIo::read(I, filename);
158
160 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080") {
161 std::vector<vpHomogeneousMatrix> cMo_vec;
162 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
163 CHECK(cMo_vec.size() == nbTags);
164 return cMo_vec;
165 };
166
167 apriltag_detector.setAprilTagQuadDecimate(2);
168 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=2") {
169 std::vector<vpHomogeneousMatrix> cMo_vec;
170 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
171 CHECK(cMo_vec.size() == nbTags);
172 return cMo_vec;
173 };
174
175 apriltag_detector.setAprilTagQuadDecimate(3);
176 BENCHMARK("Benchmark Apriltag detection: tag21_07 1920x1080 decimate=3") {
177 std::vector<vpHomogeneousMatrix> cMo_vec;
178 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
179 CHECK(cMo_vec.size() == nbTags);
180 return cMo_vec;
181 };
182 }
183
184#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
185 SECTION("tag49_12")
186 {
188 "AprilTag/benchmark/1920x1080/tag49_12_1920x1080.png");
189 REQUIRE(vpIoTools::checkFilename(filename));
191 vpImageIo::read(I, filename);
192
194 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080") {
195 std::vector<vpHomogeneousMatrix> cMo_vec;
196 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
197 CHECK(cMo_vec.size() == nbTags);
198 return cMo_vec;
199 };
200
201 apriltag_detector.setAprilTagQuadDecimate(2);
202 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=2") {
203 std::vector<vpHomogeneousMatrix> cMo_vec;
204 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
205 CHECK(cMo_vec.size() == nbTags);
206 return cMo_vec;
207 };
208
209 apriltag_detector.setAprilTagQuadDecimate(3);
210 BENCHMARK("Benchmark Apriltag detection: tag49_12 1920x1080 decimate=3") {
211 std::vector<vpHomogeneousMatrix> cMo_vec;
212 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
213 CHECK(cMo_vec.size() == nbTags);
214 return cMo_vec;
215 };
216 }
217
218 SECTION("tag48_12")
219 {
221 "AprilTag/benchmark/1920x1080/tag48_12_1920x1080.png");
222 REQUIRE(vpIoTools::checkFilename(filename));
224 vpImageIo::read(I, filename);
225
227 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080") {
228 std::vector<vpHomogeneousMatrix> cMo_vec;
229 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
230 CHECK(cMo_vec.size() == nbTags);
231 return cMo_vec;
232 };
233
234 apriltag_detector.setAprilTagQuadDecimate(2);
235 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=2") {
236 std::vector<vpHomogeneousMatrix> cMo_vec;
237 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
238 CHECK(cMo_vec.size() == nbTags);
239 return cMo_vec;
240 };
241
242 apriltag_detector.setAprilTagQuadDecimate(3);
243 BENCHMARK("Benchmark Apriltag detection: tag48_12 1920x1080 decimate=3") {
244 std::vector<vpHomogeneousMatrix> cMo_vec;
245 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
246 CHECK(cMo_vec.size() == nbTags);
247 return cMo_vec;
248 };
249 }
250
251 SECTION("tag41_12")
252 {
254 "AprilTag/benchmark/1920x1080/tag41_12_1920x1080.png");
255 REQUIRE(vpIoTools::checkFilename(filename));
257 vpImageIo::read(I, filename);
258
260 BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080") {
261 std::vector<vpHomogeneousMatrix> cMo_vec;
262 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
263 CHECK(cMo_vec.size() == nbTags);
264 return cMo_vec;
265 };
266
267 apriltag_detector.setAprilTagQuadDecimate(2);
268 BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=2") {
269 std::vector<vpHomogeneousMatrix> cMo_vec;
270 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
271 CHECK(cMo_vec.size() == nbTags);
272 return cMo_vec;
273 };
274
275 apriltag_detector.setAprilTagQuadDecimate(3);
276 BENCHMARK("Benchmark Apriltag detection: tag41_12 1920x1080 decimate=3") {
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
284 SECTION("tag52_13")
285 {
287 "AprilTag/benchmark/1920x1080/tag52_13_1920x1080.png");
288 REQUIRE(vpIoTools::checkFilename(filename));
290 vpImageIo::read(I, filename);
291
293 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080") {
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(2);
301 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=2") {
302 std::vector<vpHomogeneousMatrix> cMo_vec;
303 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
304 CHECK(cMo_vec.size() == nbTags);
305 return cMo_vec;
306 };
307
308 apriltag_detector.setAprilTagQuadDecimate(3);
309 BENCHMARK("Benchmark Apriltag detection: tag52_13 1920x1080 decimate=3") {
310 std::vector<vpHomogeneousMatrix> cMo_vec;
311 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
312 CHECK(cMo_vec.size() == nbTags);
313 return cMo_vec;
314 };
315 }
316#endif
317}
318
319TEST_CASE("Benchmark Apriltag detection 640x480", "[benchmark]") {
320 const double tagSize = 0.25;
321 const vpCameraParameters cam(700, 700, 320, 240);
322 const size_t nbTags = 5;
323
324 SECTION("tag16_05")
325 {
327 "AprilTag/benchmark/640x480/tag16_05_640x480.png");
328 REQUIRE(vpIoTools::checkFilename(filename));
330 vpImageIo::read(I, filename);
331
333 BENCHMARK("Benchmark Apriltag detection: tag16_05 640x480") {
334 std::vector<vpHomogeneousMatrix> cMo_vec;
335 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
336 CHECK(cMo_vec.size() == nbTags);
337 return cMo_vec;
338 };
339 }
340
341 SECTION("tag25_09")
342 {
344 "AprilTag/benchmark/640x480/tag25_09_640x480.png");
345 REQUIRE(vpIoTools::checkFilename(filename));
347 vpImageIo::read(I, filename);
348
350 BENCHMARK("Benchmark Apriltag detection: tag25_09 640x480") {
351 std::vector<vpHomogeneousMatrix> cMo_vec;
352 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
353 CHECK(cMo_vec.size() == nbTags);
354 return cMo_vec;
355 };
356 }
357
358 SECTION("tag36_11")
359 {
361 "AprilTag/benchmark/640x480/tag36_11_640x480.png");
362 REQUIRE(vpIoTools::checkFilename(filename));
364 vpImageIo::read(I, filename);
365
367 BENCHMARK("Benchmark Apriltag detection: tag36_11 640x480") {
368 std::vector<vpHomogeneousMatrix> cMo_vec;
369 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
370 CHECK(cMo_vec.size() == nbTags);
371 return cMo_vec;
372 };
373 }
374
375 SECTION("tag21_07")
376 {
378 "AprilTag/benchmark/640x480/tag21_07_640x480.png");
379 REQUIRE(vpIoTools::checkFilename(filename));
381 vpImageIo::read(I, filename);
382
384 BENCHMARK("Benchmark Apriltag detection: tag21_07 640x480") {
385 std::vector<vpHomogeneousMatrix> cMo_vec;
386 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
387 CHECK(cMo_vec.size() == nbTags);
388 return cMo_vec;
389 };
390 }
391
392#if defined(VISP_HAVE_APRILTAG_BIG_FAMILY)
393 SECTION("tag49_12")
394 {
396 "AprilTag/benchmark/640x480/tag49_12_640x480.png");
397 REQUIRE(vpIoTools::checkFilename(filename));
399 vpImageIo::read(I, filename);
400
402 BENCHMARK("Benchmark Apriltag detection: tag49_12 640x480") {
403 std::vector<vpHomogeneousMatrix> cMo_vec;
404 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
405 CHECK(cMo_vec.size() == nbTags);
406 return cMo_vec;
407 };
408 }
409
410 SECTION("tag48_12")
411 {
413 "AprilTag/benchmark/640x480/tag48_12_640x480.png");
414 REQUIRE(vpIoTools::checkFilename(filename));
416 vpImageIo::read(I, filename);
417
419 BENCHMARK("Benchmark Apriltag detection: tag48_12 640x480") {
420 std::vector<vpHomogeneousMatrix> cMo_vec;
421 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
422 CHECK(cMo_vec.size() == nbTags);
423 return cMo_vec;
424 };
425 }
426
427 SECTION("tag41_12")
428 {
430 "AprilTag/benchmark/640x480/tag41_12_640x480.png");
431 REQUIRE(vpIoTools::checkFilename(filename));
433 vpImageIo::read(I, filename);
434
436 BENCHMARK("Benchmark Apriltag detection: tag41_12 640x480") {
437 std::vector<vpHomogeneousMatrix> cMo_vec;
438 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
439 CHECK(cMo_vec.size() == nbTags);
440 return cMo_vec;
441 };
442 }
443
444 SECTION("tag52_13")
445 {
447 "AprilTag/benchmark/640x480/tag52_13_640x480.png");
448 REQUIRE(vpIoTools::checkFilename(filename));
450 vpImageIo::read(I, filename);
451
453 BENCHMARK("Benchmark Apriltag detection: tag52_13 640x480") {
454 std::vector<vpHomogeneousMatrix> cMo_vec;
455 apriltag_detector.detect(I, tagSize, cam, cMo_vec);
456 CHECK(cMo_vec.size() == nbTags);
457 return cMo_vec;
458 };
459 }
460#endif
461}
462
463int main(int argc, char *argv[])
464{
465 Catch::Session session; // There must be exactly one instance
466
467 bool runBenchmark = false;
468 // Build a new parser on top of Catch's
469 using namespace Catch::clara;
470 auto cli = session.cli() // Get Catch's composite command line parser
471 | Opt(runBenchmark) // bind variable to a new option, with a hint string
472 ["--benchmark"] // the option names it will respond to
473 ("run benchmark?"); // description string for the help output
474
475 // Now pass the new composite back to Catch so it uses that
476 session.cli(cli);
477
478 // Let Catch (using Clara) parse the command line
479 session.applyCommandLine(argc, argv);
480
481 if (runBenchmark) {
482 int numFailed = session.run();
483
484 // numFailed is clamped to 255 as some unices only use the lower 8 bits.
485 // This clamping has already been applied, so just return it here
486 // You can also do any post run clean-up here
487 return numFailed;
488 }
489
490 return EXIT_SUCCESS;
491}
492#else
493int main()
494{
495 return 0;
496}
497#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:149
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1365
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:802
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1670