Main MRPT website > C++ reference for MRPT 1.5.7
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 
12 
14 
15 
16 using namespace mrpt;
17 using namespace mrpt::maps;
18 using namespace mrpt::slam;
19 using namespace mrpt::utils;
20 using namespace mrpt::poses;
21 
22 
23 /*---------------------------------------------------------------
24  Constructor
25  ---------------------------------------------------------------*/
26 COccupancyGridMapFeatureExtractor::COccupancyGridMapFeatureExtractor()
27 {
28 }
29 
30 /*---------------------------------------------------------------
31  Destructor
32  ---------------------------------------------------------------*/
33 COccupancyGridMapFeatureExtractor::~COccupancyGridMapFeatureExtractor()
34 {
35 }
36 
37 
38 /*---------------------------------------------------------------
39  uncached_extractFeatures
40  ---------------------------------------------------------------*/
41 void COccupancyGridMapFeatureExtractor::uncached_extractFeatures(
44  const size_t number_of_features,
45  const mrpt::vision::TDescriptorType descriptors,
47  )
48 {
50 
51  // get the gridmap as an image:
52  CImage img(1,1,1);
53  grid.getAsImageFiltered(img, true /*vertical flip*/, false /* force RGB */ );
54 
55  // Detect features:
57  vision::CFeatureList lstFeatures;
58 
59  fExt.options = feat_options;
60  fExt.options.patchSize = 0; // Do NOT extract patch
61 
62  // Detect interest points:
63  fExt.detectFeatures( img, lstFeatures,0 /* Init ID */, number_of_features );
64 
65  // Extract descriptors:
66  if (descriptors!= mrpt::vision::descAny)
67  fExt.computeDescriptors(img, lstFeatures, descriptors);
68 
69  // Copy all the features to a map of landmarks:
70  for (vision::CFeatureList::iterator it=lstFeatures.begin();it!=lstFeatures.end();++it)
71  {
72  CLandmark lm;
73  lm.ID = (*it)->ID;
74  lm.features.resize(1);
75 
76  lm.features[0] = *it; // Insert the full feature there:
77 
78  lm.pose_mean.x = grid.getXMin() + ((*it)->x+0.5f)* grid.getResolution();
79  lm.pose_mean.y = grid.getYMin() + ((*it)->y+0.5f)* grid.getResolution();
80  lm.pose_mean.z = 0;
81 
82  lm.pose_cov_11=
83  lm.pose_cov_22=
84  lm.pose_cov_33= square(grid.getResolution());
85  lm.pose_cov_12=lm.pose_cov_13=lm.pose_cov_23 = 0;
86 
87  lm.seenTimesCount = 1;
88 
89  outMap.landmarks.push_back( lm );
90  }
91 
92  MRPT_END_WITH_CLEAN_UP( try { grid.saveMetricMapRepresentationToFile("__DEBUG_DUMP_GRIDMAP_ON_EXCEPTION"); } catch(...){} );
93 }
94 
95 /*---------------------------------------------------------------
96  extractFeatures
97  ---------------------------------------------------------------*/
98 void COccupancyGridMapFeatureExtractor::extractFeatures(
101  const size_t number_of_features,
102  const mrpt::vision::TDescriptorType descriptors,
104  )
105 {
106 #if 0
107  // Un-cashed version:
108  uncached_extractFeatures(grid,outMap,number_of_features,descriptors,feat_options);
109 #else
110  // Use cache mechanism:
111 
112  TCache::const_iterator it=m_cache.find(&grid);
113  if (it==m_cache.end())
114  {
115  // We have to recompute the features:
117 
118  uncached_extractFeatures(grid,*theMap,number_of_features,descriptors,feat_options);
119 
120  outMap = *theMap;
121 
122  // Insert into the cache:
123  m_cache[&grid] = theMap;
124  }
125  else
126  {
127  // Already in the cache:
128  outMap = *(it->second);
129  }
130 
131 #endif
132 }
133 
134 // This will receive the events from maps in order to purge the cache.
135 void COccupancyGridMapFeatureExtractor::OnEvent(const mrptEvent &e)
136 {
137  const COccupancyGridMap2D *src = NULL;
138 
139  // Upon map change or destruction, remove from our cache:
140  if (e.isOfType<mrptEventOnDestroy>()) src = static_cast<const COccupancyGridMap2D*>( static_cast<const mrptEventOnDestroy*>(&e)->source_object );
141  if (e.isOfType<mrptEventMetricMapClear>()) src = static_cast<const COccupancyGridMap2D*>( static_cast<const mrptEventMetricMapClear*>(&e)->source_map );
142  if (e.isOfType<mrptEventMetricMapInsert>()) src = static_cast<const COccupancyGridMap2D*>( static_cast<const mrptEventMetricMapClear*>(&e)->source_map );
143 
144  if (src)
145  {
146  // Remove from cache:
147  m_cache.erase(src);
148 
149  // Unsubscribe:
150  this->observeEnd( *const_cast<COccupancyGridMap2D*>(src) );
151  }
152 
153 }
154 
The class for storing "landmarks" (visual or laser-scan-extracted features,...)
mrpt::math::TPoint3D pose_mean
The mean of the landmark 3D position.
uint32_t seenTimesCount
The number of times that this landmark has been seen.
TLandmarkID ID
An ID for the landmark (see details next...) This ID was introduced in the version 3 of this class (2...
std::vector< mrpt::vision::CFeaturePtr > features
The set of features from which the landmark comes.
A class for storing a map of 3D probabilistic landmarks.
static CLandmarksMapPtr Create()
struct VISION_IMPEXP 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 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.
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const MRPT_OVERRIDE
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >,...
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:102
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:59
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 before calling "detectFeatures".
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:212
TInternalFeatList::iterator iterator
Definition: CFeature.h:261
const Scalar * const_iterator
Definition: eigen_plugins.h:24
GLuint src
Definition: glext.h:6303
GLint GLvoid * img
Definition: glext.h:3645
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:366
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: mrpt_macros.h:373
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:52
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:18
mrpt::maps::CLandmarksMapPtr CLandmarksMapPtr
Backward compatible typedef.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
Definition: zip.h:16
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 z
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.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at mar 26 may 2026 13:12:03 CEST