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-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 }
mrpt::maps::CLandmark::ID
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
mrpt::system::mrptEvent
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
mrpt::vision::CFeatureExtraction
The central class from which images can be analyzed in search of different kinds of interest points a...
Definition: CFeatureExtraction.h:82
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::vision::CFeatureExtraction::computeDescriptors
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,...
Definition: CFeatureExtraction_common.cpp:234
mrpt::maps::mrptEventMetricMapClear
Event emitted by a metric up upon call of clear()
Definition: CMetricMapEvents.h:29
mrpt::vision::TDescriptorType
TDescriptorType
The bitwise OR combination of values of TDescriptorType are used in CFeatureExtraction::computeDescri...
Definition: vision/include/mrpt/vision/types.h:95
src
GLuint src
Definition: glext.h:7278
mrpt::maps::CLandmark::seenTimesCount
uint32_t seenTimesCount
The number of times that this landmark has been seen.
Definition: CLandmark.h:79
COccupancyGridMapFeatureExtractor.h
MRPT_END_WITH_CLEAN_UP
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: exceptions.h:268
mrpt::maps::CLandmarksMap::Ptr
std::shared_ptr< CLandmarksMap > Ptr
Definition: CLandmarksMap.h:77
mrpt::math::TPoint3D::z
double z
Definition: lightweight_geom_data.h:385
mrpt::vision::CFeatureList::iterator
TInternalFeatList::iterator iterator
Definition: CFeature.h:367
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::maps::CLandmark::features
std::vector< mrpt::vision::CFeature::Ptr > features
The set of features from which the landmark comes.
Definition: CLandmark.h:44
mrpt::vision::CFeatureList::begin
iterator begin()
Definition: CFeature.h:373
mrpt::square
T square(const T x)
Inline function for the square of a number.
Definition: core/include/mrpt/core/bits_math.h:18
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::vision::CFeatureExtraction::TOptions::patchSize
unsigned int patchSize
Size of the patch to extract, or 0 if no patch is desired (default=21).
Definition: CFeatureExtraction.h:113
mrpt::vision::descAny
@ descAny
Used in some methods to mean "any of the present descriptors".
Definition: vision/include/mrpt/vision/types.h:98
mrpt::maps::CLandmark::pose_cov_12
float pose_cov_12
Definition: CLandmark.h:51
mrpt::maps::CLandmark::pose_cov_13
float pose_cov_13
Definition: CLandmark.h:51
mrpt::maps::CLandmark::pose_cov_22
float pose_cov_22
Definition: CLandmark.h:51
mrpt::system::mrptEvent::isOfType
bool isOfType() const
Definition: mrptEvent.h:42
mrpt::vision::CFeatureList
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:304
mrpt::img
Definition: CCanvas.h:17
mrpt::maps::CLandmark
The class for storing "landmarks" (visual or laser-scan-extracted features,...)
Definition: CLandmark.h:35
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::maps::CLandmarksMap::TCustomSequenceLandmarks::push_back
void push_back(const CLandmark &lm)
The object is copied, thus the original copy passed as a parameter can be released.
Definition: CLandmarksMap.cpp:1880
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::maps::CLandmarksMap::landmarks
struct mrpt::maps::CLandmarksMap::TCustomSequenceLandmarks landmarks
mrpt::vision::CFeatureExtraction::TOptions
The set of parameters for all the detectors & descriptor algorithms.
Definition: CFeatureExtraction.h:95
mrpt::maps::COccupancyGridMap2D::saveMetricMapRepresentationToFile
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >,...
Definition: COccupancyGridMap2D_io.cpp:533
mrpt::maps::COccupancyGridMap2D::getYMin
float getYMin() const
Returns the "y" coordinate of top side of grid map.
Definition: COccupancyGridMap2D.h:304
mrpt::maps::mrptEventMetricMapClear::source_map
const mrpt::maps::CMetricMap * source_map
Definition: CMetricMapEvents.h:40
mrpt::system::mrptEventOnDestroy
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:67
mrpt::vision::CFeatureExtraction::options
TOptions options
Set all the parameters of the desired method here.
Definition: CFeatureExtraction.h:317
mrpt::maps::CLandmark::pose_mean
mrpt::math::TPoint3D pose_mean
The mean of the landmark 3D position.
Definition: CLandmark.h:47
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::vision::CFeatureList::end
iterator end()
Definition: CFeature.h:374
mrpt::vision::CFeatureExtraction::detectFeatures
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.
Definition: CFeatureExtraction_common.cpp:38
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
mrpt::maps::COccupancyGridMap2D::getResolution
float getResolution() const
Returns the resolution of the grid map.
Definition: COccupancyGridMap2D.h:308
mrpt::maps::CLandmark::pose_cov_33
float pose_cov_33
Definition: CLandmark.h:51
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::maps::COccupancyGridMap2D::getXMin
float getXMin() const
Returns the "x" coordinate of left side of grid map.
Definition: COccupancyGridMap2D.h:300
slam-precomp.h
mrpt::maps::COccupancyGridMap2D
A class for storing an occupancy grid map.
Definition: COccupancyGridMap2D.h:62
mrpt::maps::CLandmarksMap
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:75
mrpt::maps
Definition: CBeacon.h:24
mrpt::maps::COccupancyGridMap2D::getAsImageFiltered
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 ...
Definition: COccupancyGridMap2D_getAs.cpp:132
mrpt::maps::CLandmark::pose_cov_11
float pose_cov_11
Definition: CLandmark.h:51
mrpt::maps::mrptEventMetricMapInsert
Event emitted by a metric up upon a succesful call to insertObservation()
Definition: CMetricMapEvents.h:47
mrpt::slam
Definition: CMultiMetricMapPDF.h:27
mrpt::maps::CLandmark::pose_cov_23
float pose_cov_23
Definition: CLandmark.h:52
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST