Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDetectorAprilTag.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 * Base class for AprilTag detection.
32 */
33#ifndef VP_DETECTOR_APRILTAG_H
34#define VP_DETECTOR_APRILTAG_H
35
36#include <map>
37
38#include <visp3/core/vpConfig.h>
39
40#ifdef VISP_HAVE_APRILTAG
41#include <visp3/core/vpCameraParameters.h>
42#include <visp3/core/vpColor.h>
43#include <visp3/core/vpHomogeneousMatrix.h>
44#include <visp3/core/vpImage.h>
45#include <visp3/detection/vpDetectorBase.h>
46
261class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase
262{
263public:
345
360
361 vpDetectorAprilTag(const vpAprilTagFamily &tagFamily = TAG_36h11,
362 const vpPoseEstimationMethod &poseEstimationMethod = HOMOGRAPHY_VIRTUAL_VS);
365 virtual ~vpDetectorAprilTag() VP_OVERRIDE;
366 bool detect(const vpImage<unsigned char> &I) VP_OVERRIDE;
367
368 bool detect(const vpImage<unsigned char> &I, double tagSize, const vpCameraParameters &cam,
369 std::vector<vpHomogeneousMatrix> &cMo_vec, std::vector<vpHomogeneousMatrix> *cMo_vec2 = nullptr,
370 std::vector<double> *projErrors = nullptr, std::vector<double> *projErrors2 = nullptr);
371
372 void displayFrames(const vpImage<unsigned char> &I, const std::vector<vpHomogeneousMatrix> &cMo_vec,
373 const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness = 1) const;
374 void displayFrames(const vpImage<vpRGBa> &I, const std::vector<vpHomogeneousMatrix> &cMo_vec,
375 const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness = 1) const;
376
377 void displayTags(const vpImage<unsigned char> &I, const std::vector<std::vector<vpImagePoint> > &tagsCorners,
378 const vpColor &color = vpColor::none, unsigned int thickness = 1) const;
379 void displayTags(const vpImage<vpRGBa> &I, const std::vector<std::vector<vpImagePoint> > &tagsCorners,
380 const vpColor &color = vpColor::none, unsigned int thickness = 1) const;
381
382 float getAprilTagDecisionMarginThreshold() const;
383 int getAprilTagHammingDistanceThreshold() const;
384 bool getPose(size_t tagIndex, double tagSize, const vpCameraParameters &cam, vpHomogeneousMatrix &cMo,
385 vpHomogeneousMatrix *cMo2 = nullptr, double *projError = nullptr, double *projError2 = nullptr);
386
391
392 bool getTagImage(vpImage<unsigned char> &I, int id);
393 std::vector<std::vector<vpImagePoint> > getTagsCorners() const;
394 std::vector<float> getTagsDecisionMargin() const;
395 std::vector<int> getTagsHammingDistance() const;
396 std::vector<int> getTagsId() const;
397 std::vector<std::vector<vpPoint> > getTagsPoints3D(const std::vector<int> &tagsId,
398 const std::map<int, double> &tagsSize) const;
399
400 bool isZAlignedWithCameraAxis() const;
401
402 void setAprilTagDebugOption(bool flag);
403 void setAprilTagDecisionMarginThreshold(float decisionMarginThreshold);
404 void setAprilTagDecodeSharpening(double decodeSharpening);
405 void setAprilTagFamily(const vpAprilTagFamily &tagFamily);
406 void setAprilTagHammingDistanceThreshold(int hammingDistanceThreshold);
407 void setAprilTagNbThreads(int nThreads);
408 void setAprilTagPoseEstimationMethod(const vpPoseEstimationMethod &poseEstimationMethod);
409 void setAprilTagQuadDecimate(float quadDecimate);
410 void setAprilTagQuadSigma(float quadSigma);
411 void setAprilTagRefineEdges(bool refineEdges);
412
413
416 inline void setDisplayTag(bool display, const vpColor &color = vpColor::none, unsigned int thickness = 2)
417 {
418 m_displayTag = display;
419 m_displayTagColor = color;
420 m_displayTagThickness = thickness;
421 }
422
423 inline friend void swap(vpDetectorAprilTag &o1, vpDetectorAprilTag &o2)
424 {
425 using std::swap;
426 swap(o1.m_impl, o2.m_impl);
427 }
428
429 void setZAlignedWithCameraAxis(bool zAlignedWithCameraFrame);
430
431#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
436 VP_DEPRECATED void setAprilTagRefinePose(bool refinePose);
437 VP_DEPRECATED void setAprilTagRefineDecode(bool refineDecode);
439#endif
440
441protected:
447
448private:
449 vpCameraParameters m_defaultCam;
450
451 // PIMPL idiom
452 class Impl;
453 Impl *m_impl;
454};
455
456inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpPoseEstimationMethod &method)
457{
458 switch (method) {
460 os << "HOMOGRAPHY";
461 break;
462
464 os << "HOMOGRAPHY_VIRTUAL_VS";
465 break;
466
468 os << "DEMENTHON_VIRTUAL_VS";
469 break;
470
472 os << "LAGRANGE_VIRTUAL_VS";
473 break;
474
476 os << "BEST_RESIDUAL_VIRTUAL_VS";
477 break;
478
480 os << "HOMOGRAPHY_ORTHOGONAL_ITERATION";
481 break;
482
483 default:
484 os << "ERROR_UNKNOWN_POSE_METHOD!";
485 break;
486 }
487
488 return os;
489}
490
491inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpAprilTagFamily &tagFamily)
492{
493 switch (tagFamily) {
495 os << "36h11";
496 break;
497
499 os << "36h10";
500 break;
501
503 os << "36artoolkit";
504 break;
505
507 os << "25h9";
508 break;
509
511 os << "25h7";
512 break;
513
515 os << "16h5";
516 break;
517
519 os << "CIRCLE21h7";
520 break;
521
523 os << "CIRCLE49h12";
524 break;
525
527 os << "CUSTOM48h12";
528 break;
529
531 os << "STANDARD52h13";
532 break;
533
535 os << "STANDARD41h12";
536 break;
537
539 os << "TAG_ARUCO_4x4_50";
540 break;
541
543 os << "TAG_ARUCO_4x4_100";
544 break;
545
547 os << "TAG_ARUCO_4x4_250";
548 break;
549
551 os << "TAG_ARUCO_4x4_1000";
552 break;
553
555 os << "TAG_ARUCO_5x5_50";
556 break;
557
559 os << "TAG_ARUCO_5x5_100";
560 break;
561
563 os << "TAG_ARUCO_5x5_250";
564 break;
565
567 os << "TAG_ARUCO_5x5_1000";
568 break;
569
571 os << "TAG_ARUCO_6x6_50";
572 break;
573
575 os << "TAG_ARUCO_6x6_100";
576 break;
577
579 os << "TAG_ARUCO_6x6_250";
580 break;
581
583 os << "TAG_ARUCO_6x6_1000";
584 break;
585
587 os << "TAG_ARUCO_7x7_50";
588 break;
589
591 os << "TAG_ARUCO_7x7_100";
592 break;
593
595 os << "TAG_ARUCO_7x7_250";
596 break;
597
599 os << "TAG_ARUCO_7x7_1000";
600 break;
601
603 os << "TAG_ARUCO_MIP_36h12";
604 break;
605
606 default:
607 os << "UNKNOWN";
608 break;
609 }
610
611 return os;
612}
613
614END_VISP_NAMESPACE
615
616#endif
617#endif
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor none
Definition vpColor.h:210
void setDisplayTag(bool display, const vpColor &color=vpColor::none, unsigned int thickness=2)
friend void swap(vpDetectorAprilTag &o1, vpDetectorAprilTag &o2)
vpPoseEstimationMethod getPoseEstimationMethod() const
vpDetectorAprilTag(const vpAprilTagFamily &tagFamily=TAG_36h11, const vpPoseEstimationMethod &poseEstimationMethod=HOMOGRAPHY_VIRTUAL_VS)
unsigned int m_displayTagThickness
vpAprilTagFamily m_tagFamily
vpPoseEstimationMethod m_poseEstimationMethod
@ TAG_CIRCLE21h7
AprilTag Circle21h7 pattern.
@ TAG_25h7
DEPRECATED AND POOR DETECTION PERFORMANCE.
@ TAG_36ARTOOLKIT
DEPRECATED AND WILL NOT DETECT ARTOOLKIT TAGS.
@ 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.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:131