Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpDetectorAprilTag.h
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  * Base class for April Tag detection.
33  *
34  *****************************************************************************/
35 #ifndef _vpDetectorAprilTag_h_
36 #define _vpDetectorAprilTag_h_
37 
38 #include <map>
39 
40 #include <visp3/core/vpConfig.h>
41 
42 #ifdef VISP_HAVE_APRILTAG
43 #include <visp3/core/vpCameraParameters.h>
44 #include <visp3/core/vpHomogeneousMatrix.h>
45 #include <visp3/core/vpImage.h>
46 #include <visp3/core/vpColor.h>
47 #include <visp3/detection/vpDetectorBase.h>
48 
216 class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase
217 {
218 public:
230  TAG_STANDARD52h13
231  };
232 
235  HOMOGRAPHY_VIRTUAL_VS,
237  DEMENTHON_VIRTUAL_VS,
239  LAGRANGE_VIRTUAL_VS,
241  BEST_RESIDUAL_VIRTUAL_VS,
244  HOMOGRAPHY_ORTHOGONAL_ITERATION
245  };
246 
247  vpDetectorAprilTag(const vpAprilTagFamily &tagFamily = TAG_36h11,
248  const vpPoseEstimationMethod &poseEstimationMethod = HOMOGRAPHY_VIRTUAL_VS);
251  virtual ~vpDetectorAprilTag();
252 
253  bool detect(const vpImage<unsigned char> &I);
254  bool detect(const vpImage<unsigned char> &I, double tagSize, const vpCameraParameters &cam,
255  std::vector<vpHomogeneousMatrix> &cMo_vec, std::vector<vpHomogeneousMatrix> *cMo_vec2=NULL,
256  std::vector<double> *projErrors=NULL, std::vector<double> *projErrors2=NULL);
257 
258  bool getPose(size_t tagIndex, double tagSize, const vpCameraParameters &cam,
259  vpHomogeneousMatrix &cMo, vpHomogeneousMatrix *cMo2=NULL,
260  double *projError=NULL, double *projError2=NULL);
261 
265  inline vpPoseEstimationMethod getPoseEstimationMethod() const { return m_poseEstimationMethod; }
266 
267  std::vector<std::vector<vpImagePoint> > getTagsCorners() const;
268  std::vector<int> getTagsId() const;
269  std::vector<std::vector<vpPoint> > getTagsPoints3D(const std::vector<int>& tagsId, const std::map<int, double>& tagsSize) const;
270 
271  void setAprilTagDecodeSharpening(double decodeSharpening);
272  void setAprilTagFamily(const vpAprilTagFamily &tagFamily);
273  void setAprilTagNbThreads(int nThreads);
274  void setAprilTagPoseEstimationMethod(const vpPoseEstimationMethod &poseEstimationMethod);
275  void setAprilTagQuadDecimate(float quadDecimate);
276  void setAprilTagQuadSigma(float quadSigma);
277  void setAprilTagRefineDecode(bool refineDecode);
278  void setAprilTagRefineEdges(bool refineEdges);
279  void setAprilTagRefinePose(bool refinePose);
280 
283  inline void setDisplayTag(bool display, const vpColor &color=vpColor::none,
284  unsigned int thickness=2) {
285  m_displayTag = display;
286  m_displayTagColor = color;
287  m_displayTagThickness = thickness;
288  }
289 
290  friend void swap(vpDetectorAprilTag &o1, vpDetectorAprilTag &o2);
291 
292  void setZAlignedWithCameraAxis(bool zAlignedWithCameraFrame);
293 
294 protected:
297  unsigned int m_displayTagThickness;
300 
301 private:
302  vpCameraParameters m_defaultCam;
303 
304  // PIMPL idiom
305  class Impl;
306  Impl *m_impl;
307 };
308 
309 inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpPoseEstimationMethod &method)
310 {
311  switch (method) {
313  os << "HOMOGRAPHY";
314  break;
315 
317  os << "HOMOGRAPHY_VIRTUAL_VS";
318  break;
319 
321  os << "DEMENTHON_VIRTUAL_VS";
322  break;
323 
325  os << "LAGRANGE_VIRTUAL_VS";
326  break;
327 
329  os << "BEST_RESIDUAL_VIRTUAL_VS";
330  break;
331 
333  os << "HOMOGRAPHY_ORTHOGONAL_ITERATION";
334  break;
335 
336  default:
337  os << "ERROR_UNKNOWN_POSE_METHOD!";
338  break;
339  }
340 
341  return os;
342 }
343 
344 inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpAprilTagFamily &tagFamily)
345 {
346  switch (tagFamily) {
348  os << "36h11";
349  break;
350 
352  os << "36h10";
353  break;
354 
356  os << "36artoolkit";
357  break;
358 
360  os << "25h9";
361  break;
362 
364  os << "25h7";
365  break;
366 
368  os << "16h5";
369  break;
370 
372  os << "CIRCLE21h7";
373  break;
374 
376  os << "CIRCLE49h12";
377  break;
378 
380  os << "CUSTOM48h12";
381  break;
382 
384  os << "STANDARD52h13";
385  break;
386 
388  os << "STANDARD41h12";
389  break;
390 
391  default:
392  break;
393  }
394 
395  return os;
396 }
397 
398 #endif
399 #endif
AprilTag 16h5 pattern.
AprilTag Standard52h13 pattern.
DEPRECATED AND WILL NOT DETECT ARTOOLKIT TAGS.
Implementation of an homogeneous matrix and operations on such kind of matrices.
AprilTag 36h11 pattern (recommended)
vpPoseEstimationMethod getPoseEstimationMethod() const
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
AprilTag Circle21h7 pattern.
static const vpColor none
Definition: vpColor.h:229
virtual bool detect(const vpImage< unsigned char > &I)=0
AprilTag Circle49h12 pattern.
Generic class defining intrinsic camera parameters.
vpPoseEstimationMethod m_poseEstimationMethod
AprilTag Standard41h12 pattern.
void setDisplayTag(bool display, const vpColor &color=vpColor::none, unsigned int thickness=2)
AprilTag Custom48h12 pattern.
unsigned int m_displayTagThickness
vpAprilTagFamily m_tagFamily
AprilTag 25h9 pattern.
DEPRECATED AND POOR DETECTION PERFORMANCE.