MRPT  2.0.4
COccupancyGridMapFeatureExtractor.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "slam-precomp.h" // Precompiled headers
11 
13 
14 using namespace mrpt;
15 using namespace mrpt::maps;
16 using namespace mrpt::slam;
17 using namespace mrpt::poses;
18 using namespace mrpt::img;
19 using namespace mrpt::system;
20 
21 void COccupancyGridMapFeatureExtractor::uncached_extractFeatures(
23  mrpt::maps::CLandmarksMap& outMap, const size_t number_of_features,
24  const mrpt::vision::TDescriptorType descriptors,
26 {
28 
29  // get the gridmap as an image:
30  CImage img;
31  grid.getAsImageFiltered(img, true /*vertical flip*/, false /* force RGB */);
32 
33  // Detect features:
35  vision::CFeatureList lstFeatures;
36 
37  fExt.options = feat_options;
38  fExt.options.patchSize = 0; // Do NOT extract patch
39 
40  // Detect interest points:
41  fExt.detectFeatures(img, lstFeatures, 0 /* Init ID */, number_of_features);
42 
43  // Extract descriptors:
44  if (descriptors != mrpt::vision::descAny)
45  fExt.computeDescriptors(img, lstFeatures, descriptors);
46 
47  // Copy all the features to a map of landmarks:
48  for (auto& ft : lstFeatures)
49  {
50  CLandmark lm;
51  lm.ID = ft.keypoint.ID;
52  lm.features.resize(1);
53 
54  lm.features[0] = ft; // Insert the full feature there:
55 
56  lm.pose_mean.x =
57  grid.getXMin() + (ft.keypoint.pt.x + 0.5f) * grid.getResolution();
58  lm.pose_mean.y =
59  grid.getYMin() + (ft.keypoint.pt.y + 0.5f) * grid.getResolution();
60  lm.pose_mean.z = 0;
61 
62  lm.pose_cov_11 = lm.pose_cov_22 = lm.pose_cov_33 =
63  square(grid.getResolution());
64  lm.pose_cov_12 = lm.pose_cov_13 = lm.pose_cov_23 = 0;
65 
66  lm.seenTimesCount = 1;
67 
68  outMap.landmarks.push_back(lm);
69  }
70 
73  "__DEBUG_DUMP_GRIDMAP_ON_EXCEPTION");
74  } catch (...){});
75 }
76 
77 /*---------------------------------------------------------------
78  extractFeatures
79  ---------------------------------------------------------------*/
80 void COccupancyGridMapFeatureExtractor::extractFeatures(
82  mrpt::maps::CLandmarksMap& outMap, const size_t number_of_features,
83  const mrpt::vision::TDescriptorType descriptors,
85 {
86 #if 0
87  // Un-cashed version:
88  uncached_extractFeatures(grid,outMap,number_of_features,descriptors,feat_options);
89 #else
90  // Use cache mechanism:
91 
92  auto it = m_cache.find(&grid);
93  if (it == m_cache.end())
94  {
95  // We have to recompute the features:
96  CLandmarksMap::Ptr theMap = std::make_shared<CLandmarksMap>();
97 
98  uncached_extractFeatures(
99  grid, *theMap, number_of_features, descriptors, feat_options);
100 
101  outMap = *theMap;
102 
103  // Insert into the cache:
104  m_cache[&grid] = theMap;
105  }
106  else
107  {
108  // Already in the cache:
109  outMap = *(it->second);
110  }
111 
112 #endif
113 }
114 
115 // This will receive the events from maps in order to purge the cache.
116 void COccupancyGridMapFeatureExtractor::OnEvent(const mrptEvent& e)
117 {
118  const COccupancyGridMap2D* src = nullptr;
119 
120  // Upon map change or destruction, remove from our cache:
121  if (e.isOfType<mrptEventOnDestroy>())
122  src = static_cast<const COccupancyGridMap2D*>(
123  static_cast<const mrptEventOnDestroy*>(&e)->source_object);
125  src = static_cast<const COccupancyGridMap2D*>(
126  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
128  src = static_cast<const COccupancyGridMap2D*>(
129  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
130 
131  if (src)
132  {
133  // Remove from cache:
134  m_cache.erase(src);
135 
136  // Unsubscribe:
137  this->observeEnd(*const_cast<COccupancyGridMap2D*>(src));
138  }
139 }
float getYMin() const
Returns the "y" coordinate of top side of grid map.
#define MRPT_START
Definition: exceptions.h:241
float getResolution() const
Returns the resolution of the grid map.
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >...
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:31
void detectFeatures(const mrpt::img::CImage &img, CFeatureList &feats, const unsigned int init_ID=0, const unsigned int nDesiredFeatures=0, const TImageROI &ROI=TImageROI())
Extract features from the image based on the method defined in TOptions.
TOptions options
Set all the parameters of the desired method here before calling detectFeatures() ...
The set of parameters for all the detectors & descriptor algorithms.
void getAsImageFiltered(img::CImage &img, bool verticalFlip=false, bool forceRGB=false) const
Returns the grid as a 8-bit graylevel image, where each pixel is a cell (output image is RGB only if ...
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: exceptions.h:247
Used in some methods to mean "any of the present descriptors".
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:74
float getXMin() const
Returns the "x" coordinate of left side of grid map.
void push_back(const CLandmark &lm)
The object is copied, thus the original copy passed as a parameter can be released.
TDescriptorType
The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescri...
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:66
Event emitted by a metric up upon a succesful call to insertObservation()
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:275
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Event emitted by a metric up upon call of clear()
return_t square(const num_t x)
Inline function for the square of a number.
A class for storing an occupancy grid map.
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The class for storing "landmarks" (visual or laser-scan-extracted features,...)
Definition: CLandmark.h:35
bool isOfType() const
Definition: mrptEvent.h:41
std::vector< mrpt::vision::CFeature > features
The set of features from which the landmark comes.
Definition: CLandmark.h:44
mrpt::math::TPoint3D pose_mean
The mean of the landmark 3D position.
Definition: CLandmark.h:47
unsigned int patchSize
Size of the patch to extract, or 0 if no patch is desired (default=21).
void computeDescriptors(const mrpt::img::CImage &in_img, CFeatureList &inout_features, TDescriptorType in_descriptor_list)
Compute one (or more) descriptors for the given set of interest points onto the image, which may have been filled out manually or from detectFeatures.
uint32_t seenTimesCount
The number of times that this landmark has been seen.
Definition: CLandmark.h:81
struct mrpt::maps::CLandmarksMap::TCustomSequenceLandmarks landmarks
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
The central class from which images can be analyzed in search of different kinds of interest points a...
TLandmarkID ID
An ID for the landmark (see details next...) This ID was introduced in the version 3 of this class (2...
Definition: CLandmark.h:75



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020