18 #include <mrpt/otherlibs/do_opencv_includes.h> 33 unsigned int nDesiredFeatures,
const TImageROI& ROI)
const 38 #if MRPT_OPENCV_VERSION_NUM < 0x300 43 vector<KeyPoint> cv_feats;
47 #if MRPT_OPENCV_VERSION_NUM >= 0x300 49 const Mat theImg = cvarrToMat(inImg_gray.
getAs<IplImage>());
50 Ptr<AKAZE> akaze = AKAZE::create(
51 options.AKAZEOptions.descriptor_type,
52 options.AKAZEOptions.descriptor_size,
53 options.AKAZEOptions.descriptor_channels,
54 options.AKAZEOptions.threshold, options.AKAZEOptions.nOctaves,
55 options.AKAZEOptions.nOctaveLayers, options.AKAZEOptions.diffusivity);
57 akaze->detect(theImg, cv_feats);
60 const size_t N = cv_feats.size();
64 for (
size_t i = 0; i < N; i++)
66 for (
size_t j = i + 1; j < N; j++)
68 if (cv_feats.at(j).response > cv_feats.at(i).response)
70 KeyPoint temp_point = cv_feats.at(i);
71 cv_feats.at(i) = cv_feats.at(j);
72 cv_feats.at(j) = temp_point;
78 (nDesiredFeatures != 0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
79 const int offset = (int)this->options.patchSize / 2 + 1;
80 const size_t size_2 = options.patchSize / 2;
82 const size_t imgW = inImg.
getWidth();
84 unsigned int cont = 0;
87 if (!options.addNewFeatures) feats.
clear();
89 while (cont != nMax && i != N)
92 const KeyPoint& kp = cv_feats[i];
96 const int xBorderInf = (int)floor(kp.pt.x - size_2);
97 const int xBorderSup = (int)floor(kp.pt.x + size_2);
98 const int yBorderInf = (int)floor(kp.pt.y - size_2);
99 const int yBorderSup = (int)floor(kp.pt.y + size_2);
101 if (!(xBorderSup < (
int)imgW && xBorderInf > 0 &&
102 yBorderSup < (int)imgH && yBorderInf > 0))
111 ft->response = kp.response;
112 ft->orientation = kp.angle;
113 ft->scale = kp.octave;
114 ft->patchSize = options.patchSize;
116 if (options.patchSize > 0)
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.
uint64_t TFeatureID
Definition of a feature ID.
#define THROW_EXCEPTION(msg)
size_t getHeight() const override
Returns the height of the image in pixels.
A structure for defining a ROI within an image.
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
Classes for computer vision, detectors, features, etc.
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)...
AKAZE detector, OpenCV's implementation.
void push_back(const CFeature::Ptr &f)
A class for storing images as grayscale or RGB bitmaps.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
int round(const T value)
Returns the closer integer (int) to x.