16 #include <mrpt/otherlibs/do_opencv_includes.h> 17 #ifdef HAVE_OPENCV_NONFREE // MRPT_HAS_OPENCV_NONFREE 18 #include <opencv2/nonfree/nonfree.hpp> 20 #ifdef HAVE_OPENCV_FEATURES2D 21 #include <opencv2/features2d/features2d.hpp> 23 #ifdef HAVE_OPENCV_XFEATURES2D 24 #include <opencv2/xfeatures2d.hpp> 40 unsigned int nDesiredFeatures,
const TImageROI& ROI)
44 bool usingROI =
false;
64 img_grayscale.
swap(auximg);
67 switch (options.SIFTOptions.implementation)
72 "CSBinary SIFT not available since MRPT 1.9.9: " 73 "Use `OpenCV` version");
79 "Vedaldi SIFT not available since MRPT 1.9.9: " 80 "Use `OpenCV` version");
86 "LoweBinary not available since MRPT 1.9.9: " 87 "Use `OpenCV` version");
93 "Hess SIFT not available since MRPT 1.9.9: " 94 "Use `OpenCV` version");
102 #if defined(HAVE_OPENCV_NONFREE) || defined(HAVE_OPENCV_XFEATURES2D) 104 #if MRPT_OPENCV_VERSION_NUM < 0x300 105 SiftFeatureDetector SIFTDetector(
106 options.SIFTOptions.threshold,
107 options.SIFTOptions.edgeThreshold);
109 SiftDescriptorExtractor SIFTDescriptor;
110 vector<KeyPoint> cv_feats;
111 const Mat& theImg = img_grayscale.
asCvMatRef();
112 SIFTDetector.detect(theImg, cv_feats);
114 SIFTDescriptor.compute(theImg, cv_feats, desc);
118 vector<KeyPoint> cv_feats;
120 auto sift = cv::xfeatures2d::SIFT::create(
121 nDesiredFeatures, options.SIFTOptions.octaveLayers,
122 options.SIFTOptions.threshold,
123 options.SIFTOptions.edgeThreshold, 1.6);
124 const Mat& theImg = img_grayscale.
asCvMatRef();
126 sift->detectAndCompute(theImg, noArray() , cv_feats, desc);
128 const size_t N = cv_feats.size();
130 unsigned int nMax = nDesiredFeatures != 0 && N > nDesiredFeatures
133 const int offset = (int)this->options.patchSize / 2 + 1;
134 const size_t size_2 = options.patchSize / 2;
135 const size_t imgH =
img.getHeight();
136 const size_t imgW =
img.getWidth();
138 unsigned int cont = 0;
142 while (cont != nMax && i != N)
144 const int xBorderInf = (int)floor(cv_feats[i].pt.x - size_2);
145 const int xBorderSup = (int)floor(cv_feats[i].pt.x + size_2);
146 const int yBorderInf = (int)floor(cv_feats[i].pt.y - size_2);
147 const int yBorderSup = (int)floor(cv_feats[i].pt.y + size_2);
149 if (options.patchSize == 0 ||
150 ((xBorderSup < (
int)imgW) && (xBorderInf > 0) &&
151 (yBorderSup < (int)imgH) && (yBorderInf > 0)))
167 out_desc.resize(128);
169 &out_desc[0], &desc.data[128 * i],
170 128 *
sizeof(out_desc[0]));
172 if (options.patchSize > 0)
189 "This method requires OpenCV >= 2.1.1 with nonfree module");
206 profiler,
"internal_computeSiftDescriptors");
211 "SIFT Extraction method not supported for features with already known " 212 "image coordinates");
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.
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Scale Invariant Feature Transform [LOWE'04].
TFeatureID ID
ID of the feature.
void swap(CImage &o)
Efficiently swap of two images.
float yMin
Y coordinate limits [0,imageHeight)
A structure for defining a ROI within an image.
#define ASSERT_(f)
Defines an assertion mechanism.
void push_back(const CFeature &f)
This base provides a set of functions for maths stuff.
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 xMin
X coordinate limits [0,imageWidth)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::optional< std::vector< uint8_t > > SIFT
SIFT feature descriptor.
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.
float response
A measure of the "goodness" of the feature (typically, the KLT_response value)
uint16_t patchSize
Size of the patch (patchSize x patchSize) (it must be an odd number)
pixel_coords_t pt
Coordinates in the image.
A class for storing images as grayscale or RGB bitmaps.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
int round(const T value)
Returns the closer integer (int) to x.