Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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 <visp3/core/vpConfig.h>
39 
40 #ifdef VISP_HAVE_APRILTAG
41 #include <visp3/core/vpCameraParameters.h>
42 #include <visp3/core/vpHomogeneousMatrix.h>
43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpColor.h>
45 #include <visp3/detection/vpDetectorBase.h>
46 
213 class VISP_EXPORT vpDetectorAprilTag : public vpDetectorBase
214 {
215 
216 public:
218  TAG_36h11,
221  TAG_36h10,
224  TAG_36ARTOOLKIT,
226  TAG_25h9,
229  TAG_25h7,
232  TAG_16h5
235  };
236 
239  HOMOGRAPHY_VIRTUAL_VS,
241  DEMENTHON_VIRTUAL_VS,
243  LAGRANGE_VIRTUAL_VS,
245  BEST_RESIDUAL_VIRTUAL_VS
248  };
249 
250  vpDetectorAprilTag(const vpAprilTagFamily &tagFamily = TAG_36h11,
251  const vpPoseEstimationMethod &poseEstimationMethod = HOMOGRAPHY_VIRTUAL_VS);
252  virtual ~vpDetectorAprilTag();
253 
254  bool detect(const vpImage<unsigned char> &I);
255  bool detect(const vpImage<unsigned char> &I, const double tagSize, const vpCameraParameters &cam,
256  std::vector<vpHomogeneousMatrix> &cMo_vec);
257 
258  bool getPose(size_t tagIndex, const double tagSize, const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
259 
263  inline vpPoseEstimationMethod getPoseEstimationMethod() const { return m_poseEstimationMethod; }
264 
265  void setAprilTagNbThreads(const int nThreads);
266  void setAprilTagPoseEstimationMethod(const vpPoseEstimationMethod &poseEstimationMethod);
267  void setAprilTagQuadDecimate(const float quadDecimate);
268  void setAprilTagQuadSigma(const float quadSigma);
269  void setAprilTagRefineDecode(const bool refineDecode);
270  void setAprilTagRefineEdges(const bool refineEdges);
271  void setAprilTagRefinePose(const bool refinePose);
272 
275  inline void setDisplayTag(const bool display, const vpColor &color=vpColor::none,
276  const unsigned int thickness=2) {
277  m_displayTag = display;
278  m_displayTagColor = color;
279  m_displayTagThickness = thickness;
280  }
281 
282  void setZAlignedWithCameraAxis(bool zAlignedWithCameraFrame);
283 
284 protected:
287  unsigned int m_displayTagThickness;
291 
292 private:
293  vpDetectorAprilTag(const vpDetectorAprilTag &); // noncopyable
294  vpDetectorAprilTag &operator=(const vpDetectorAprilTag &); //
295 
296  // PIMPL idiom
297  class Impl;
298  Impl *m_impl;
299 };
300 
301 inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpPoseEstimationMethod &method)
302 {
303  switch (method) {
305  os << "HOMOGRAPHY";
306  break;
307 
309  os << "HOMOGRAPHY_VIRTUAL_VS";
310  break;
311 
313  os << "DEMENTHON_VIRTUAL_VS";
314  break;
315 
317  os << "LAGRANGE_VIRTUAL_VS";
318  break;
319 
321  os << "BEST_RESIDUAL_VIRTUAL_VS";
322  break;
323 
324  default:
325  os << "ERROR_UNKNOWN_POSE_METHOD!";
326  break;
327  }
328 
329  return os;
330 }
331 
332 inline std::ostream &operator<<(std::ostream &os, const vpDetectorAprilTag::vpAprilTagFamily &tagFamily)
333 {
334  switch (tagFamily) {
336  os << "36h11";
337  break;
338 
340  os << "36h10";
341  break;
342 
344  os << "36artoolkit";
345  break;
346 
348  os << "25h9";
349  break;
350 
352  os << "25h7";
353  break;
354 
356  os << "16h5";
357  break;
358 
359  default:
360  break;
361  }
362 
363  return os;
364 }
365 
366 #endif
367 #endif
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static const vpColor none
Definition: vpColor.h:192
vpPoseEstimationMethod getPoseEstimationMethod() const
virtual bool detect(const vpImage< unsigned char > &I)=0
Generic class defining intrinsic camera parameters.
vpPoseEstimationMethod m_poseEstimationMethod
unsigned int m_displayTagThickness
vpAprilTagFamily m_tagFamily
void setDisplayTag(const bool display, const vpColor &color=vpColor::none, const unsigned int thickness=2)