MRPT  2.0.3
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 }
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:31
mrpt::vision::CFeatureExtraction
The central class from which images can be analyzed in search of different kinds of interest points a...
Definition: CFeatureExtraction.h:71
mrpt::maps::mrptEventMetricMapClear
Event emitted by a metric up upon call of clear()
Definition: CMetricMapEvents.h:28
mrpt::maps::CLandmark::seenTimesCount
uint32_t seenTimesCount
The number of times that this landmark has been seen.
Definition: CLandmark.h:81
mrpt::vision::CFeatureExtraction::computeDescriptors
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,...
Definition: CFeatureExtraction_common.cpp:86
COccupancyGridMapFeatureExtractor.h
mrpt::math::TPoint3D_data::z
T z
Definition: TPoint3D.h:29
MRPT_END_WITH_CLEAN_UP
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: exceptions.h:247
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
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:104
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:52
mrpt::maps::CLandmark::pose_cov_22
float pose_cov_22
Definition: CLandmark.h:51
mrpt::system::mrptEvent::isOfType
bool isOfType() const
Definition: mrptEvent.h:41
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())
Extract features from the image based on the method defined in TOptions.
Definition: CFeatureExtraction_common.cpp:37
mrpt::vision::CFeatureList
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition: CFeature.h:275
mrpt::img
Definition: CCanvas.h:16
mrpt::maps::CLandmarksMap::Ptr
std::shared_ptr< mrpt::maps ::CLandmarksMap > Ptr
Definition: CLandmarksMap.h:76
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:241
mrpt::maps::CLandmark::features
std::vector< mrpt::vision::CFeature > features
The set of features from which the landmark comes.
Definition: CLandmark.h:44
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:1806
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:87
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:523
mrpt::maps::COccupancyGridMap2D::getYMin
float getYMin() const
Returns the "y" coordinate of top side of grid map.
Definition: COccupancyGridMap2D.h:282
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:66
mrpt::square
return_t square(const num_t x)
Inline function for the square of a number.
Definition: core/include/mrpt/core/bits_math.h:23
mrpt::vision::CFeatureExtraction::options
TOptions options
Set all the parameters of the desired method here before calling detectFeatures()
Definition: CFeatureExtraction.h:295
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:148
mrpt::math::TPoint3D_data::y
T y
Definition: TPoint3D.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:76
mrpt::maps::COccupancyGridMap2D::getResolution
float getResolution() const
Returns the resolution of the grid map.
Definition: COccupancyGridMap2D.h:286
mrpt::maps::CLandmark::pose_cov_33
float pose_cov_33
Definition: CLandmark.h:51
mrpt::maps::COccupancyGridMap2D::getXMin
float getXMin() const
Returns the "x" coordinate of left side of grid map.
Definition: COccupancyGridMap2D.h:278
slam-precomp.h
mrpt::math::TPoint3D_data::x
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
mrpt::maps::COccupancyGridMap2D
A class for storing an occupancy grid map.
Definition: COccupancyGridMap2D.h:53
mrpt::maps::CLandmarksMap
A class for storing a map of 3D probabilistic landmarks.
Definition: CLandmarksMap.h:74
mrpt::maps
Definition: CBeacon.h:21
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:26
mrpt::maps::CLandmark::pose_cov_23
float pose_cov_23
Definition: CLandmark.h:52
mrpt::vision::descAny
@ descAny
Used in some methods to mean "any of the present descriptors".
Definition: vision/include/mrpt/vision/types.h:79
mrpt::system
Definition: backtrace.h:14



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020