15 #include <mrpt/otherlibs/do_opencv_includes.h> 33 unsigned int nDesiredFeatures,
41 # if MRPT_OPENCV_VERSION_NUM < 0x210 47 vector<KeyPoint> cv_feats;
56 #if MRPT_OPENCV_VERSION_NUM >= 0x211 62 const Mat theImg = cvarrToMat( inImg_gray.
getAs<IplImage>() );
67 cout <<
"using mask" << endl;
68 size_t maskW =
mask->getColCount(), maskH =
mask->getRowCount();
73 for(
int ii = 0; ii < int(maskW); ++ii )
74 for(
int jj = 0; jj < int(maskH); ++jj )
76 if( !
mask->get_unsafe(jj,ii) )
78 cvMask.at<
char>(ii,jj) = (
char)0;
84 # if MRPT_OPENCV_VERSION_NUM < 0x300 85 FastFeatureDetector fastDetector( options.FASTOptions.threshold, options.FASTOptions.nonmax_suppression );
86 fastDetector.detect( theImg, cv_feats );
88 Ptr<cv::FastFeatureDetector> fastDetector = cv::FastFeatureDetector::create(options.FASTOptions.threshold, options.FASTOptions.nonmax_suppression );
89 fastDetector->detect( theImg, cv_feats );
92 #elif MRPT_OPENCV_VERSION_NUM >= 0x210 93 FAST(inImg_gray.
getAs<IplImage>(), cv_feats, options.FASTOptions.threshold, options.FASTOptions.nonmax_suppression );
97 const size_t N = cv_feats.size();
100 if (options.FASTOptions.use_KLT_response)
102 const unsigned int KLT_half_win = 4;
103 const unsigned int max_x = inImg_gray.
getWidth() - 1 - KLT_half_win;
104 const unsigned int max_y = inImg_gray.
getHeight() - 1 - KLT_half_win;
105 for (
size_t i=0;i<N;i++)
107 const unsigned int x = cv_feats[i].pt.x;
108 const unsigned int y = cv_feats[i].pt.y;
109 if (
x>KLT_half_win &&
y>KLT_half_win &&
x<=max_x &&
y<=max_y)
111 else cv_feats[i].response = -100;
118 std::vector<size_t> sorted_indices(N);
119 for (
size_t i=0;i<N;i++) sorted_indices[i]=i;
130 const bool do_filter_min_dist = options.FASTOptions.min_distance>1;
133 const unsigned int occupied_grid_cell_size = options.FASTOptions.min_distance/2.0;
134 const float occupied_grid_cell_size_inv = 1.0f/occupied_grid_cell_size;
136 unsigned int grid_lx = !do_filter_min_dist ? 1 : (
unsigned int)(1 + inImg.
getWidth() * occupied_grid_cell_size_inv);
137 unsigned int grid_ly = !do_filter_min_dist ? 1 : (
unsigned int)(1 + inImg.
getHeight() * occupied_grid_cell_size_inv );
140 occupied_sections.
fillAll(
false);
143 unsigned int nMax = (nDesiredFeatures!=0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
144 const int offset = (int)this->options.patchSize/2 + 1;
145 const size_t size_2 = options.patchSize/2;
147 const size_t imgW = inImg.
getWidth();
149 unsigned int cont = 0;
152 if( !options.addNewFeatures )
155 while( cont != nMax && i!=N )
158 const KeyPoint &kp = cv_feats[ sorted_indices[i] ];
162 const int xBorderInf = (int)floor( kp.pt.x - size_2 );
163 const int xBorderSup = (int)floor( kp.pt.x + size_2 );
164 const int yBorderInf = (int)floor( kp.pt.y - size_2 );
165 const int yBorderSup = (int)floor( kp.pt.y + size_2 );
167 if (!( xBorderSup < (
int)imgW && xBorderInf > 0 && yBorderSup < (int)imgH && yBorderInf > 0 ))
170 if (do_filter_min_dist)
173 const size_t section_idx_x = size_t(kp.pt.x * occupied_grid_cell_size_inv);
174 const size_t section_idx_y = size_t(kp.pt.y * occupied_grid_cell_size_inv);
176 if (occupied_sections(section_idx_x,section_idx_y))
180 occupied_sections.
set_unsafe(section_idx_x,section_idx_y,
true);
181 if (section_idx_x>0) occupied_sections.
set_unsafe(section_idx_x-1,section_idx_y,
true);
182 if (section_idx_y>0) occupied_sections.
set_unsafe(section_idx_x,section_idx_y-1,
true);
183 if (section_idx_x<grid_lx-1) occupied_sections.
set_unsafe(section_idx_x+1,section_idx_y,
true);
184 if (section_idx_y<grid_ly-1) occupied_sections.
set_unsafe(section_idx_x,section_idx_y+1,
true);
193 ft->response = kp.response;
194 ft->orientation = kp.angle;
195 ft->scale = kp.octave;
196 ft->patchSize = options.patchSize;
198 if( options.patchSize > 0 )
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Declares a matrix of booleans (non serializable).
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
A class for storing images as grayscale or RGB bitmaps.
#define THROW_EXCEPTION(msg)
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
FAST feature detector, OpenCV's implementation ("Faster and better: A machine learning approach to co...
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.
This base provides a set of functions for maths stuff.
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...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Classes for computer vision, detectors, features, etc.
void push_back(const CFeaturePtr &f)
uint64_t TFeatureID
Definition of a feature ID.
void set_unsafe(size_t row, size_t col, const T &v)
Fast but unsafe method to write a value in the matrix.
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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)...
int round(const T value)
Returns the closer integer (int) to x.
static CFeaturePtr Create()
EIGEN_STRONG_INLINE void ones(const size_t row, const size_t col)
Resize matrix and set all elements to one.
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels.
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.
void fillAll(const T &val)