15 #include <mrpt/3rdparty/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;
    52     const bool use_harris = (options.featsType == 
featHarris);
    54     std::vector<cv::Point2f> points;
    55     profiler.enter(
"extractFeaturesKLT.goodFeaturesToTrack");
    57     cv::goodFeaturesToTrack(
    59         (
double)options.harrisOptions.threshold,  
    62         (
double)options.harrisOptions
    67         options.harrisOptions.k);
    69     profiler.leave(
"extractFeaturesKLT.goodFeaturesToTrack");
    71     const unsigned int count = points.size();
    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;
    95     const int limit = min(nPts, count);
    96     int offset = (int)this->options.patchSize / 2 + 1;
    98     unsigned int imgW = inImg.
getWidth();
   100     const float W = options.patchSize * 0.5f;
   102     for (; i < limit; i++)
   104         const int xBorderInf = (int)floor(points[i].x - W);
   105         const int xBorderSup = (int)floor(points[i].x + W);
   106         const int yBorderInf = (int)floor(points[i].y - W);
   107         const int yBorderSup = (int)floor(points[i].y + W);
   109         if (options.patchSize != 0 &&
   110             ((xBorderSup >= (
int)imgW) || (xBorderInf < 0) ||
   111              (yBorderSup >= (int)imgH) || (yBorderInf < 0)))
   128         if (options.patchSize > 0)
   142     THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
 
#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. 
 
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.