Main MRPT website > C++ reference for 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-2017, 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::utils;
18 using namespace mrpt::poses;
19 
20 /*---------------------------------------------------------------
21  Constructor
22  ---------------------------------------------------------------*/
23 COccupancyGridMapFeatureExtractor::COccupancyGridMapFeatureExtractor() {}
24 /*---------------------------------------------------------------
25  Destructor
26  ---------------------------------------------------------------*/
27 COccupancyGridMapFeatureExtractor::~COccupancyGridMapFeatureExtractor() {}
28 /*---------------------------------------------------------------
29  uncached_extractFeatures
30  ---------------------------------------------------------------*/
31 void COccupancyGridMapFeatureExtractor::uncached_extractFeatures(
33  mrpt::maps::CLandmarksMap& outMap, const size_t number_of_features,
34  const mrpt::vision::TDescriptorType descriptors,
36 {
38 
39  // get the gridmap as an image:
40  CImage img(1, 1, 1);
41  grid.getAsImageFiltered(img, true /*vertical flip*/, false /* force RGB */);
42 
43  // Detect features:
45  vision::CFeatureList lstFeatures;
46 
47  fExt.options = feat_options;
48  fExt.options.patchSize = 0; // Do NOT extract patch
49 
50  // Detect interest points:
51  fExt.detectFeatures(img, lstFeatures, 0 /* Init ID */, number_of_features);
52 
53  // Extract descriptors:
54  if (descriptors != mrpt::vision::descAny)
55  fExt.computeDescriptors(img, lstFeatures, descriptors);
56 
57  // Copy all the features to a map of landmarks:
58  for (vision::CFeatureList::iterator it = lstFeatures.begin();
59  it != lstFeatures.end(); ++it)
60  {
61  CLandmark lm;
62  lm.ID = (*it)->ID;
63  lm.features.resize(1);
64 
65  lm.features[0] = *it; // Insert the full feature there:
66 
67  lm.pose_mean.x =
68  grid.getXMin() + ((*it)->x + 0.5f) * grid.getResolution();
69  lm.pose_mean.y =
70  grid.getYMin() + ((*it)->y + 0.5f) * grid.getResolution();
71  lm.pose_mean.z = 0;
72 
73  lm.pose_cov_11 = lm.pose_cov_22 = lm.pose_cov_33 =
74  square(grid.getResolution());
75  lm.pose_cov_12 = lm.pose_cov_13 = lm.pose_cov_23 = 0;
76 
77  lm.seenTimesCount = 1;
78 
79  outMap.landmarks.push_back(lm);
80  }
81 
84  "__DEBUG_DUMP_GRIDMAP_ON_EXCEPTION");
85  } catch (...){});
86 }
87 
88 /*---------------------------------------------------------------
89  extractFeatures
90  ---------------------------------------------------------------*/
91 void COccupancyGridMapFeatureExtractor::extractFeatures(
93  mrpt::maps::CLandmarksMap& outMap, const size_t number_of_features,
94  const mrpt::vision::TDescriptorType descriptors,
96 {
97 #if 0
98  // Un-cashed version:
99  uncached_extractFeatures(grid,outMap,number_of_features,descriptors,feat_options);
100 #else
101  // Use cache mechanism:
102 
103  TCache::const_iterator it = m_cache.find(&grid);
104  if (it == m_cache.end())
105  {
106  // We have to recompute the features:
107  CLandmarksMap::Ptr theMap = mrpt::make_aligned_shared<CLandmarksMap>();
108 
109  uncached_extractFeatures(
110  grid, *theMap, number_of_features, descriptors, feat_options);
111 
112  outMap = *theMap;
113 
114  // Insert into the cache:
115  m_cache[&grid] = theMap;
116  }
117  else
118  {
119  // Already in the cache:
120  outMap = *(it->second);
121  }
122 
123 #endif
124 }
125 
126 // This will receive the events from maps in order to purge the cache.
127 void COccupancyGridMapFeatureExtractor::OnEvent(const mrptEvent& e)
128 {
129  const COccupancyGridMap2D* src = nullptr;
130 
131  // Upon map change or destruction, remove from our cache:
132  if (e.isOfType<mrptEventOnDestroy>())
133  src = static_cast<const COccupancyGridMap2D*>(
134  static_cast<const mrptEventOnDestroy*>(&e)->source_object);
136  src = static_cast<const COccupancyGridMap2D*>(
137  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
139  src = static_cast<const COccupancyGridMap2D*>(
140  static_cast<const mrptEventMetricMapClear*>(&e)->source_map);
141 
142  if (src)
143  {
144  // Remove from cache:
145  m_cache.erase(src);
146 
147  // Unsubscribe:
148  this->observeEnd(*const_cast<COccupancyGridMap2D*>(src));
149  }
150 }
The class for storing "landmarks" (visual or laser-scan-extracted features,...)
Definition: CLandmark.h:36
mrpt::math::TPoint3D pose_mean
The mean of the landmark 3D position.
Definition: CLandmark.h:47
uint32_t seenTimesCount
The number of times that this landmark has been seen.
Definition: CLandmark.h:79
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
std::vector< mrpt::vision::CFeature::Ptr > features
The set of features from which the landmark comes.
Definition: CLandmark.h:44
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(utils::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()
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:119
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:35
bool isOfType() const
Definition: mrptEvent.h:43
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:69
The central class from which images can be analyzed in search of different kinds of interest points a...
void computeDescriptors(const mrpt::utils::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,...
void detectFeatures(const mrpt::utils::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.
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:306
TInternalFeatList::iterator iterator
Definition: CFeature.h:366
const Scalar * const_iterator
Definition: eigen_plugins.h:27
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".
#define MRPT_START
Definition: mrpt_macros.h:425
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: mrpt_macros.h:431
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:55
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:18
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST