18 #include <mrpt/otherlibs/do_opencv_includes.h> 33 unsigned int nDesiredFeatures,
const TImageROI& ROI)
40 #if MRPT_OPENCV_VERSION_NUM < 0x300 45 vector<KeyPoint> cv_feats;
49 #if MRPT_OPENCV_VERSION_NUM >= 0x300 52 Ptr<AKAZE> akaze = AKAZE::create(
53 #
if MRPT_OPENCV_VERSION_NUM >= 0x400
54 static_cast<cv::AKAZE::DescriptorType>(
55 options.AKAZEOptions.descriptor_type),
57 options.AKAZEOptions.descriptor_type,
59 options.AKAZEOptions.descriptor_size,
60 options.AKAZEOptions.descriptor_channels,
61 options.AKAZEOptions.threshold, options.AKAZEOptions.nOctaves,
62 options.AKAZEOptions.nOctaveLayers,
63 #
if MRPT_OPENCV_VERSION_NUM >= 0x400
64 static_cast<cv::KAZE::DiffusivityType>(options.AKAZEOptions.diffusivity)
66 options.AKAZEOptions.diffusivity
70 akaze->detect(theImg, cv_feats);
73 const size_t N = cv_feats.size();
77 for (
size_t i = 0; i < N; i++)
79 for (
size_t j = i + 1; j < N; j++)
81 if (cv_feats.at(j).response > cv_feats.at(i).response)
83 KeyPoint temp_point = cv_feats.at(i);
84 cv_feats.at(i) = cv_feats.at(j);
85 cv_feats.at(j) = temp_point;
91 (nDesiredFeatures != 0 && N > nDesiredFeatures) ? nDesiredFeatures : N;
92 const int offset = (int)this->options.patchSize / 2 + 1;
93 const size_t size_2 = options.patchSize / 2;
95 const size_t imgW = inImg.
getWidth();
97 unsigned int cont = 0;
100 if (!options.addNewFeatures) feats.
clear();
102 while (cont != nMax && i != N)
105 const KeyPoint& kp = cv_feats[i];
109 const int xBorderInf = (int)floor(kp.pt.x - size_2);
110 const int xBorderSup = (int)floor(kp.pt.x + size_2);
111 const int yBorderInf = (int)floor(kp.pt.y - size_2);
112 const int yBorderSup = (int)floor(kp.pt.y + size_2);
114 if (!(xBorderSup < (
int)imgW && xBorderInf > 0 &&
115 yBorderSup < (int)imgH && yBorderInf > 0))
129 if (options.patchSize > 0)
Shallow copy: the copied object is a reference to the original one.
uint64_t TFeatureID
Definition of a feature ID.
#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.
size_t getHeight() const override
Returns the height of the image in pixels.
TFeatureID ID
ID of the feature.
void asCvMat(cv::Mat &out_img, copy_type_t copy_type) const
Makes a shallow or deep copy of this image into the provided cv::Mat.
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.
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.
AKAZE detector, OpenCV's implementation.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint8_t octave
The image octave the image was found in: 0=original image, 1=1/2 image, 2=1/4 image, etc.
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)...
float orientation
Main orientation of the feature.
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.
#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.