MRPT  1.9.9
COccupancyGridMapFeatureExtractor.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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(1, 1, 1);
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 (vision::CFeatureList::iterator it = lstFeatures.begin();
49  it != lstFeatures.end(); ++it)
50  {
51  CLandmark lm;
52  lm.ID = (*it)->ID;
53  lm.features.resize(1);
54 
55  lm.features[0] = *it; // Insert the full feature there:
56 
57  lm.pose_mean.x =
58  grid.getXMin() + ((*it)->x + 0.5f) * grid.getResolution();
59  lm.pose_mean.y =
60  grid.getYMin() + ((*it)->y + 0.5f) * grid.getResolution();
61  lm.pose_mean.z = 0;
62 
63  lm.pose_cov_11 = lm.pose_cov_22 = lm.pose_cov_33 =
64  square(grid.getResolution());
65  lm.pose_cov_12 = lm.pose_cov_13 = lm.pose_cov_23 = 0;
66 
67  lm.seenTimesCount = 1;
68 
69  outMap.landmarks.push_back(lm);
70  }
71 
74  "__DEBUG_DUMP_GRIDMAP_ON_EXCEPTION");
75  } catch (...){});
76 }
77 
78 /*---------------------------------------------------------------
79  extractFeatures
80  ---------------------------------------------------------------*/
81 void COccupancyGridMapFeatureExtractor::extractFeatures(
83  mrpt::maps::CLandmarksMap& outMap, const size_t number_of_features,
84  const mrpt::vision::TDescriptorType descriptors,
86 {
87 #if 0
88  // Un-cashed version:
89  uncached_extractFeatures(grid,outMap,number_of_features,descriptors,feat_options);
90 #else
91  // Use cache mechanism:
92 
93  TCache::const_iterator it = m_cache.find(&grid);
94  if (it == m_cache.end())
95  {
96  // We have to recompute the features:
97  CLandmarksMap::Ptr theMap = mrpt::make_aligned_shared<CLandmarksMap>();
98 
99  uncached_extractFeatures(
100  grid, *theMap, number_of_features, descriptors, feat_options);
101 
102  outMap = *theMap;
103 
104  // Insert into the cache:
105  m_cache[&grid] = theMap;
106  }
107  else
108  {
109  // Already in the cache:
110  outMap = *(it->second);
111  }
112 
113 #endif
114 }
115 
116 // This will receive the events from maps in order to purge the cache.
117 void COccupancyGridMapFeatureExtractor::OnEvent(const mrptEvent& e)
118 {
119  const COccupancyGridMap2D* src = nullptr;
120 
121  // Upon map change or destruction, remove from our cache:
122  if (e.isOfType<mrptEventOnDestroy>())
123  src = static_cast<const COccupancyGridMap2D*>(
124  static_cast<const mrptEventOnDestroy*>(&e)->source_object);
126  src = static_cast<const COccupancyGridMap2D*>(
127  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
129  src = static_cast<const COccupancyGridMap2D*>(
130  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
131 
132  if (src)
133  {
134  // Remove from cache:
135  m_cache.erase(src);
136 
137  // Unsubscribe:
138  this->observeEnd(*const_cast<COccupancyGridMap2D*>(src));
139  }
140 }
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:131
The class for storing "landmarks" (visual or laser-scan-extracted features,...)
Definition: CLandmark.h:34
mrpt::math::TPoint3D pose_mean
The mean of the landmark 3D position.
Definition: CLandmark.h:45
uint32_t seenTimesCount
The number of times that this landmark has been seen.
Definition: CLandmark.h:77
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:73
std::vector< mrpt::vision::CFeature::Ptr > features
The set of features from which the landmark comes.
Definition: CLandmark.h:42
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:76
std::shared_ptr< CLandmarksMap > Ptr
Definition: CLandmarksMap.h:77
struct mrpt::maps::CLandmarksMap::TCustomSequenceLandmarks landmarks
A class for storing an occupancy grid map.
float getResolution() const
Returns the resolution of the grid map.
float getYMin() const
Returns the "y" coordinate of top side of grid map.
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >,...
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 ...
float getXMin() const
Returns the "x" coordinate of left side of grid map.
Event emitted by a metric up upon call of clear()
const mrpt::maps::CMetricMap * source_map
Event emitted by a metric up upon a succesful call to insertObservation()
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
bool isOfType() const
Definition: mrptEvent.h:41
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:67
The central class from which images can be analyzed in search of different kinds of interest points a...
void detectFeatures(const mrpt::img::CImage &img, CFeatureList &feats, const unsigned int init_ID=0, const unsigned int nDesiredFeatures=0, const TImageROI &ROI=TImageROI()) const
Extract features from the image based on the method defined in TOptions.
TOptions options
Set all the parameters of the desired method here.
void computeDescriptors(const mrpt::img::CImage &in_img, CFeatureList &inout_features, TDescriptorType in_descriptor_list) const
Compute one (or more) descriptors for the given set of interest points onto the image,...
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:305
TInternalFeatList::iterator iterator
Definition: CFeature.h:365
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define MRPT_START
Definition: exceptions.h:262
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: exceptions.h:268
GLuint src
Definition: glext.h:7278
GLint GLvoid * img
Definition: glext.h:3763
TDescriptorType
The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescri...
@ descAny
Used in some methods to mean "any of the present descriptors".
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
T square(const T x)
Inline function for the square of a number.
void push_back(const CLandmark &lm)
The object is copied, thus the original copy passed as a parameter can be released.
double x
X,Y,Z coordinates.
The set of parameters for all the detectors & descriptor algorithms.
unsigned int patchSize
Size of the patch to extract, or 0 if no patch is desired (default=21).



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST