18 #include <mrpt/otherlibs/do_opencv_includes.h> 32 unsigned int nDesiredFeatures,
const TImageROI& ROI)
const 37 #if MRPT_OPENCV_VERSION_NUM < 0x300 42 vector<KeyPoint> cv_feats;
46 #if MRPT_OPENCV_VERSION_NUM >= 0x300 48 const Mat theImg = cvarrToMat(inImg_gray.
getAs<IplImage>());
49 Ptr<AKAZE> akaze = AKAZE::create(
50 options.AKAZEOptions.descriptor_type,
51 options.AKAZEOptions.descriptor_size,
52 options.AKAZEOptions.descriptor_channels,
53 options.AKAZEOptions.threshold, options.AKAZEOptions.nOctaves,
54 options.AKAZEOptions.nOctaveLayers, options.AKAZEOptions.diffusivity);
56 akaze->detect(theImg, cv_feats);
59 const size_t N = cv_feats.size();
63 for (
size_t i = 0; i < N; i++)
65 for (
size_t j = i + 1; j < N; j++)
67 if (cv_feats.at(j).response > cv_feats.at(i).response)
69 KeyPoint temp_point = cv_feats.at(i);
70 cv_feats.at(i) = cv_feats.at(j);
71 cv_feats.at(j) = temp_point;
77 (nDesiredFeatures != 0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
78 const int offset = (int)this->options.patchSize / 2 + 1;
79 const size_t size_2 = options.patchSize / 2;
81 const size_t imgW = inImg.
getWidth();
83 unsigned int cont = 0;
86 if (!options.addNewFeatures) feats.
clear();
88 while (cont != nMax && i != N)
91 const KeyPoint& kp = cv_feats[i];
95 const int xBorderInf = (int)floor(kp.pt.x - size_2);
96 const int xBorderSup = (int)floor(kp.pt.x + size_2);
97 const int yBorderInf = (int)floor(kp.pt.y - size_2);
98 const int yBorderSup = (int)floor(kp.pt.y + size_2);
100 if (!(xBorderSup < (
int)imgW && xBorderInf > 0 &&
101 yBorderSup < (int)imgH && yBorderInf > 0))
110 ft->response = kp.response;
111 ft->orientation = kp.angle;
112 ft->scale = kp.octave;
113 ft->patchSize = options.patchSize;
115 if (options.patchSize > 0)
std::shared_ptr< CFeature > Ptr
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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.
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.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
size_t getHeight() const override
Returns the height of the image in pixels.
Classes for computer vision, detectors, features, etc.
uint64_t TFeatureID
Definition of a feature ID.
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.
AKAZE detector, OpenCV's implementation.
void push_back(const CFeature::Ptr &f)