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)