AliceVision
Photogrammetric Computer Vision Framework
ImageDescriber_APRILTAG.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2016 AliceVision contributors.
3 // Copyright (c) 2012 openMVG contributors.
4 // This Source Code Form is subject to the terms of the Mozilla Public License,
5 // v. 2.0. If a copy of the MPL was not distributed with this file,
6 // You can obtain one at https://mozilla.org/MPL/2.0/.
7 
8 #pragma once
9 
10 #include <aliceVision/feature/imageDescriberCommon.hpp>
11 #include <aliceVision/feature/ImageDescriber.hpp>
12 #include <aliceVision/feature/regionsFactory.hpp>
13 #include <aliceVision/types.hpp>
14 
15 #include <iostream>
16 #include <numeric>
17 
18 namespace aliceVision {
19 namespace feature {
20 
25 {
26  public:
27  explicit ImageDescriber_APRILTAG();
28 
29  ~ImageDescriber_APRILTAG() override = default;
30 
35  bool useCuda() const override { return false; }
36 
41  bool useFloatImage() const override { return false; }
42 
47  EImageDescriberType getDescriberType() const override;
48 
56  std::size_t getMemoryConsumption(std::size_t width, std::size_t height) const override
57  {
58  // this should be a reasonably safe upper bound, but to know this exactly,
59  // much deeper exmination of the AprilTag source code would be needed:
60  return 3 * width * height * sizeof(unsigned char);
61  }
62 
68  void setConfigurationPreset(ConfigurationPreset preset) override;
69 
78  bool describe(const image::Image<unsigned char>& image,
79  std::unique_ptr<Regions>& regions,
80  const image::Image<unsigned char>* mask = nullptr) override;
81 
86  void allocate(std::unique_ptr<Regions>& regions) const override;
87 
89  {
90  explicit AprilTagParameters() = default;
91 
92  ~AprilTagParameters() = default;
93 
94  void setPreset(EImageDescriberPreset preset);
95  };
96 
97  private:
98  // AprilTag parameters
99  AprilTagParameters _params;
100 };
101 
107 template<class DescriptorT>
108 IndexT getAprilTagId(const DescriptorT& desc)
109 {
110  std::size_t apriltagId = UndefinedIndexT;
111  for (std::size_t i = 0; i < desc.size(); ++i)
112  {
113  if (desc.getData()[i] == (unsigned char)255)
114  {
115  if (apriltagId != UndefinedIndexT)
116  {
117  return UndefinedIndexT;
118  }
119  apriltagId = i;
120  }
121  else if (desc.getData()[i] != (unsigned char)0)
122  {
123  return UndefinedIndexT;
124  }
125  }
126  return apriltagId;
127 }
128 
129 } // namespace feature
130 } // namespace aliceVision
aliceVision::feature::ImageDescriber_APRILTAG::getMemoryConsumption
std::size_t getMemoryConsumption(std::size_t width, std::size_t height) const override
Get the total amount of RAM needed for a feature extraction of an image of the given dimension.
Definition: ImageDescriber_APRILTAG.hpp:56
aliceVision::feature::ImageDescriber_APRILTAG::allocate
void allocate(std::unique_ptr< Regions > &regions) const override
Allocate Regions type depending of the ImageDescriber.
Definition: ImageDescriber_APRILTAG.cpp:24
aliceVision::feature::ImageDescriber_APRILTAG::setConfigurationPreset
void setConfigurationPreset(ConfigurationPreset preset) override
Use a preset to control the number of detected regions.
Definition: ImageDescriber_APRILTAG.cpp:26
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::feature::ImageDescriber
A pure virtual class for image description computation.
Definition: ImageDescriber.hpp:159
aliceVision::image::Image< unsigned char >
aliceVision::feature::ImageDescriber_APRILTAG::describe
bool describe(const image::Image< unsigned char > &image, std::unique_ptr< Regions > &regions, const image::Image< unsigned char > *mask=nullptr) override
Detect regions on the 8-bit image and compute their attributes (description)
Definition: ImageDescriber_APRILTAG.cpp:30
aliceVision::feature::ImageDescriber_APRILTAG
Create an ImageDescriber interface for AprilTag feature extractor.
Definition: ImageDescriber_APRILTAG.hpp:24
aliceVision::feature::ConfigurationPreset
Definition: ImageDescriber.hpp:118
aliceVision::feature::ImageDescriber_APRILTAG::useCuda
bool useCuda() const override
Check if the image describer use CUDA.
Definition: ImageDescriber_APRILTAG.hpp:35
aliceVision::feature::ImageDescriber_APRILTAG::useFloatImage
bool useFloatImage() const override
Check if the image describer use float image.
Definition: ImageDescriber_APRILTAG.hpp:41
aliceVision::feature::ImageDescriber_APRILTAG::AprilTagParameters
Definition: ImageDescriber_APRILTAG.hpp:88
aliceVision::feature::ImageDescriber_APRILTAG::getDescriberType
EImageDescriberType getDescriberType() const override
Get the corresponding EImageDescriberType.
Definition: ImageDescriber_APRILTAG.cpp:28