15 #include <mrpt/otherlibs/do_opencv_includes.h> 27 void CFeatureExtraction::extractFeaturesKLT(
29 unsigned int nDesiredFeatures,
const TImageROI& ROI)
35 const unsigned int MAX_COUNT = 300;
40 profiler.enter(
"extractFeaturesKLT.img2gray");
43 const cv::Mat& cGrey = inImg_gray.
asCvMatRef();
45 profiler.leave(
"extractFeaturesKLT.img2gray");
47 const auto nPts = (nDesiredFeatures <= 0) ? MAX_COUNT : nDesiredFeatures;
49 const auto count = nPts;
54 const bool use_harris = (options.featsType ==
featHarris);
56 std::vector<cv::Point2f>
points;
57 profiler.enter(
"extractFeaturesKLT.goodFeaturesToTrack");
59 cv::goodFeaturesToTrack(
61 (
double)options.harrisOptions.threshold,
64 (
double)options.harrisOptions
69 options.harrisOptions.k);
71 profiler.leave(
"extractFeaturesKLT.goodFeaturesToTrack");
73 if (nDesiredFeatures > 0 &&
count < nPts)
74 cout <<
"\n[WARNING][selectGoodFeaturesKLT]: Only " <<
count <<
" of " 75 << nDesiredFeatures <<
" points could be extracted in the image." 78 if (options.FIND_SUBPIXEL && !
points.empty())
80 profiler.enter(
"extractFeaturesKLT.cornerSubPix");
83 cGrey,
points, cv::Size(3, 3), cv::Size(-1, -1),
84 cv::TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10, 0.05));
86 profiler.leave(
"extractFeaturesKLT.cornerSubPix");
92 unsigned int borderFeats = 0;
93 unsigned int nCFeats = init_ID;
96 int offset = (int)this->options.patchSize / 2 + 1;
98 unsigned int imgW = inImg.
getWidth();
102 const int xBorderInf = (int)floor(
points[i].
x - options.patchSize / 2);
103 const int xBorderSup = (int)floor(
points[i].
x + options.patchSize / 2);
104 const int yBorderInf = (int)floor(
points[i].
y - options.patchSize / 2);
105 const int yBorderSup = (int)floor(
points[i].
y + options.patchSize / 2);
107 if (options.patchSize == 0 ||
108 ((xBorderSup < (
int)imgW) && (xBorderInf > 0) &&
109 (yBorderSup < (int)imgH) && (yBorderInf > 0)))
122 if (options.patchSize > 0)
141 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
GLuint GLuint GLsizei count
#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.
TFeatureTrackStatus track_status
Status of the feature tracking process.
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.
GLsizei const GLfloat * points
A structure for defining a ROI within an image.
size_t getWidth() const override
Returns the width of the image in pixels.
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...
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.
Harris border and corner detector [HARRIS].
Kanade-Lucas-Tomasi feature [SHI'94].
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)...
Feature correctly tracked.
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.