15 #include <mrpt/3rdparty/do_opencv_includes.h>    27     unsigned int nDesiredFeatures)
    36     vector<KeyPoint> cv_feats;  
    42 #if MRPT_OPENCV_VERSION_NUM < 0x300    43     FastFeatureDetector fastDetector(
    44         options.FASTOptions.threshold, options.FASTOptions.nonmax_suppression);
    45     fastDetector.detect(theImg, cv_feats);
    47     Ptr<cv::FastFeatureDetector> fastDetector = cv::FastFeatureDetector::create(
    48         options.FASTOptions.threshold, options.FASTOptions.nonmax_suppression);
    49     fastDetector->detect(theImg, cv_feats);
    53     const size_t N = cv_feats.size();
    56     if (options.FASTOptions.use_KLT_response)
    58         const unsigned int KLT_half_win = 4;
    59         const unsigned int max_x = inImg_gray.
getWidth() - 1 - KLT_half_win;
    60         const unsigned int max_y = inImg_gray.
getHeight() - 1 - KLT_half_win;
    61         for (
size_t i = 0; i < N; i++)
    63             const unsigned int x = 
mrpt::round(cv_feats[i].pt.x);
    64             const unsigned int y = 
mrpt::round(cv_feats[i].pt.y);
    65             if (x > KLT_half_win && y > KLT_half_win && x <= max_x &&
    67                 cv_feats[i].response =
    70                 cv_feats[i].response = -100;
    78     std::vector<size_t> sorted_indices(N);
    79     for (
size_t i = 0; i < N; i++) sorted_indices[i] = i;
    81         sorted_indices.begin(), sorted_indices.end(),
    96     const bool do_filter_min_dist = options.FASTOptions.min_distance > 1;
   100     const float occupied_grid_cell_size = options.FASTOptions.min_distance / 2;
   101     const float occupied_grid_cell_size_inv = 1.0f / occupied_grid_cell_size;
   103     unsigned int grid_lx =
   106             : (
unsigned int)(1 + inImg.
getWidth() * occupied_grid_cell_size_inv);
   107     unsigned int grid_ly =
   110             : (
unsigned int)(1 + inImg.
getHeight() * occupied_grid_cell_size_inv);
   113     occupied_sections.
fill(
false);
   116         (nDesiredFeatures != 0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
   117     const int offset = (int)this->options.patchSize / 2 + 1;
   118     const size_t size_2 = options.patchSize / 2;
   120     const size_t imgW = inImg.
getWidth();
   122     unsigned int cont = 0;
   125     if (!options.addNewFeatures) feats.
clear();
   127     while (cont != nMax && i != N)
   130         const KeyPoint& kp = cv_feats[sorted_indices[i]];
   134         const int xBorderInf = (int)floor(kp.pt.x - size_2);
   135         const int xBorderSup = (int)floor(kp.pt.x + size_2);
   136         const int yBorderInf = (int)floor(kp.pt.y - size_2);
   137         const int yBorderSup = (int)floor(kp.pt.y + size_2);
   139         if (!(xBorderSup < (
int)imgW && xBorderInf > 0 &&
   140               yBorderSup < (int)imgH && yBorderInf > 0))
   143         if (do_filter_min_dist)
   146             const auto sect_ix = size_t(kp.pt.x * occupied_grid_cell_size_inv);
   147             const auto sect_iy = size_t(kp.pt.y * occupied_grid_cell_size_inv);
   149             if (occupied_sections(sect_ix, sect_iy))
   153             occupied_sections(sect_ix, sect_iy) = 
true;
   154             if (sect_ix > 0) occupied_sections(sect_ix - 1, sect_iy) = 
true;
   155             if (sect_iy > 0) occupied_sections(sect_ix, sect_iy - 1) = 
true;
   156             if (sect_ix < grid_lx - 1)
   157                 occupied_sections(sect_ix + 1, sect_iy) = 
true;
   158             if (sect_iy < grid_ly - 1)
   159                 occupied_sections(sect_ix, sect_iy + 1) = 
true;
   173         if (options.patchSize > 0)
 Shallow copy: the copied object is a reference to the original one. 
 
uint64_t TFeatureID
Definition of a feature ID. 
 
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)
 
size_t getHeight() const override
Returns the height of the image in pixels. 
 
TFeatureID ID
ID of the feature. 
 
void asCvMat(cv::Mat &out_img, copy_type_t copy_type) const
Makes a shallow or deep copy of this image into the provided cv::Mat. 
 
A helper struct to sort keypoints by their response: It can be used with these types: ...
 
This base provides a set of functions for maths stuff. 
 
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. 
 
Classes for computer vision, detectors, features, etc. 
 
A generic 2D feature from an image, extracted with CFeatureExtraction Each feature may have one or mo...
 
FAST feature detector, OpenCV's implementation ("Faster and better: A    machine learning approach to...
 
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. 
 
uint8_t octave
The image octave the image was found in: 0=original image, 1=1/2 image, 2=1/4 image, etc. 
 
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. 
 
This template class provides the basic functionality for a general 2D any-size, resizable container o...
 
uint16_t patchSize
Size of the patch (patchSize x patchSize) (it must be an odd number) 
 
void emplace_back(CFeature &&f)
 
pixel_coords_t pt
Coordinates in the image. 
 
A class for storing images as grayscale or RGB bitmaps. 
 
int round(const T value)
Returns the closer integer (int) to x.