15 #include <mrpt/otherlibs/do_opencv_includes.h> 32 bool append_to_list,
uint8_t octave,
33 std::vector<size_t>* out_feats_index_by_row)
37 if (!append_to_list) corners.
clear();
41 out_feats_index_by_row);
48 bool append_to_list,
uint8_t octave,
49 std::vector<size_t>* out_feats_index_by_row)
53 if (!append_to_list) corners.
clear();
57 out_feats_index_by_row);
64 bool append_to_list,
uint8_t octave,
65 std::vector<size_t>* out_feats_index_by_row)
69 if (!append_to_list) corners.
clear();
73 out_feats_index_by_row);
82 unsigned int init_ID,
unsigned int nDesiredFeatures,
const TImageROI& ROI)
101 img, corners, options.FASTOptions.threshold, 0,
nullptr);
106 img, corners, options.FASTOptions.threshold, 0,
nullptr);
111 img, corners, options.FASTOptions.threshold, 0,
nullptr);
116 "Only the 9,10,12 FASTER detectors are implemented.");
122 const size_t N = corners.
size();
128 std::vector<size_t> sorted_indices(N);
129 std::iota(sorted_indices.begin(), sorted_indices.end(), 0);
134 if (options.FASTOptions.use_KLT_response || nDesiredFeatures != 0)
136 const auto KLT_half_win =
137 options.FASTOptions.KLT_response_half_win_size;
139 static_cast<int>(inImg_gray.
getWidth() - 1 - KLT_half_win);
141 static_cast<int>(inImg_gray.
getHeight() - 1 - KLT_half_win);
143 for (
size_t i = 0; i < N; i++)
145 const auto x = corners[i].pt.x;
146 const auto y = corners[i].pt.y;
147 if (
x > KLT_half_win &&
y > KLT_half_win &&
x <= max_x &&
149 corners[i].response =
152 corners[i].response = -100;
156 sorted_indices.begin(), sorted_indices.end(),
161 for (
size_t i = 0; i < N; i++) corners[i].response = 0;
176 const bool do_filter_min_dist = options.FASTOptions.min_distance > 1;
180 const unsigned int occupied_grid_cell_size =
181 options.FASTOptions.min_distance / 2.0;
182 const float occupied_grid_cell_size_inv = 1.0f / occupied_grid_cell_size;
184 unsigned int grid_lx =
187 : (
unsigned int)(1 + inImg.
getWidth() * occupied_grid_cell_size_inv);
188 unsigned int grid_ly =
191 : (
unsigned int)(1 + inImg.
getHeight() * occupied_grid_cell_size_inv);
195 occupied_sections.
fill(
false);
198 (nDesiredFeatures != 0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
199 const int offset = (int)this->options.patchSize / 2 + 1;
200 const int size_2 = options.patchSize / 2;
202 const size_t imgW = inImg.
getWidth();
204 unsigned int cont = 0;
207 if (!options.addNewFeatures) feats.
clear();
209 while (cont != nMax && i != N)
212 const TKeyPoint& feat = corners[sorted_indices[i]];
216 const int xBorderInf = feat.
pt.x - size_2;
217 const int xBorderSup = feat.
pt.x + size_2;
218 const int yBorderInf = feat.
pt.y - size_2;
219 const int yBorderSup = feat.
pt.y + size_2;
221 if (!(xBorderSup < (
int)imgW && xBorderInf > 0 &&
222 yBorderSup < (
int)imgH && yBorderInf > 0))
225 if (do_filter_min_dist)
229 size_t(feat.
pt.x * occupied_grid_cell_size_inv);
231 size_t(feat.
pt.y * occupied_grid_cell_size_inv);
233 if (occupied_sections(sect_ix, sect_iy))
237 occupied_sections(sect_ix, sect_iy) =
true;
238 if (sect_ix > 0) occupied_sections(sect_ix - 1, sect_iy) =
true;
239 if (sect_iy > 0) occupied_sections(sect_ix, sect_iy - 1) =
true;
240 if (sect_ix < grid_lx - 1)
241 occupied_sections(sect_ix + 1, sect_iy) =
true;
242 if (sect_iy < grid_ly - 1)
243 occupied_sections(sect_ix, sect_iy + 1) =
true;
248 ft.
type = type_of_this_feature;
257 if (options.patchSize > 0)
Shallow copy: the copied object is a reference to the original one.
uint64_t TFeatureID
Definition of a feature ID.
#define THROW_EXCEPTION(msg)
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
TKeyPointMethod type
Keypoint method used to detect this feature.
void fill(const Scalar &val)
void fast_corner_detect_10(const cv::Mat &I, TKeyPointList &corners, int barrier, uint8_t octave, std::vector< size_t > *out_feats_index_by_row)
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
size_t getHeight() const override
Returns the height of the image in pixels.
TFeatureID ID
ID of the feature.
Simple structure for image key points.
static void detectFeatures_SSE2_FASTER10(const mrpt::img::CImage &img, TKeyPointList &corners, const int threshold=20, bool append_to_list=false, uint8_t octave=0, std::vector< size_t > *out_feats_index_by_row=nullptr)
Just like detectFeatures_SSE2_FASTER9() for another version of the detector.
A helper struct to sort keypoints by their response: It can be used with these types: ...
A structure for defining a ROI within an image.
#define ASSERT_(f)
Defines an assertion mechanism.
void push_back(const CFeature &f)
size_t getWidth() const override
Returns the width of the image in pixels.
float KLT_response(const unsigned int x, const unsigned int y, const unsigned int half_window_size) const
Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids...
std::optional< mrpt::img::CImage > patch
A patch of the image surrounding the feature.
void fast_corner_detect_9(const cv::Mat &I, TKeyPointList &corners, int barrier, uint8_t octave, std::vector< size_t > *out_feats_index_by_row)
TKeyPointMethod
Types of key point detectors.
Classes for computer vision, detectors, features, etc.
A generic 2D feature from an image, extracted with CFeatureExtraction Each feature may have one or mo...
FASTER-9 detector, Edward Rosten's libcvd, SSE2 optimized.
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
float response
A measure of the "goodness" of the feature.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
FASTER-9 detector, Edward Rosten's libcvd, SSE2 optimized.
uint8_t octave
The image octave the image was found in: 0=original image, 1=1/2 image, 2=1/4 image, etc.
static void detectFeatures_SSE2_FASTER9(const mrpt::img::CImage &img, TKeyPointList &corners, const int threshold=20, bool append_to_list=false, uint8_t octave=0, std::vector< size_t > *out_feats_index_by_row=nullptr)
A SSE2-optimized implementation of FASTER-9 (requires img to be grayscale).
void extract_patch(CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten)...
float orientation
Main orientation of the feature.
static void detectFeatures_SSE2_FASTER12(const mrpt::img::CImage &img, TKeyPointList &corners, const int threshold=20, bool append_to_list=false, uint8_t octave=0, std::vector< size_t > *out_feats_index_by_row=nullptr)
Just like detectFeatures_SSE2_FASTER9() for another version of the detector.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
float response
A measure of the "goodness" of the feature (typically, the KLT_response value)
uint16_t patchSize
Size of the patch (patchSize x patchSize) (it must be an odd number)
void fast_corner_detect_12(const cv::Mat &I, TKeyPointList &corners, int barrier, uint8_t octave, std::vector< size_t > *out_feats_index_by_row)
pixel_coords_t pt
Coordinates in the image.
A class for storing images as grayscale or RGB bitmaps.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
FASTER-9 detector, Edward Rosten's libcvd, SSE2 optimized.
int round(const T value)
Returns the closer integer (int) to x.