OpenCV  4.5.1
Open Source Computer Vision
Feature Description

Table of Contents

Prev Tutorial: Feature Detection
Next Tutorial: Feature Matching with FLANN

Original author Ana Huamán
Compatibility OpenCV >= 3.0

Goal

In this tutorial you will learn how to:

  • Use the cv::DescriptorExtractor interface in order to find the feature vector correspondent to the keypoints. Specifically:
    • Use cv::xfeatures2d::SURF and its function cv::xfeatures2d::SURF::compute to perform the required calculations.
    • Use a cv::DescriptorMatcher to match the features vector
    • Use the function cv::drawMatches to draw the detected matches.
Warning
You need the OpenCV contrib modules to be able to use the SURF features (alternatives are ORB, KAZE, ... features).

Theory

Code

Explanation

Result

Here is the result after applying the BruteForce matcher between the two original images:

cv::noArray
InputOutputArray noArray()
cv::String
std::string String
Definition: cvstd.hpp:150
cv::imread
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
cv::MatExpr::max
MatExpr max(const Mat &a, const Mat &b)
cv::samples::findFile
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
cv::DescriptorMatcher::BRUTEFORCE
@ BRUTEFORCE
Definition: features2d.hpp:957
cv::waitKey
int waitKey(int delay=0)
Waits for a pressed key.
highgui.hpp
core.hpp
cv::Mat::empty
bool empty() const
Returns true if the array has no elements.
cv::DescriptorMatcher::match
void match(InputArray queryDescriptors, InputArray trainDescriptors, std::vector< DMatch > &matches, InputArray mask=noArray()) const
Finds the best match for each descriptor from a query set.
cv::IMREAD_GRAYSCALE
@ IMREAD_GRAYSCALE
If set, always convert image to the single channel grayscale image (codec internal conversion).
Definition: imgcodecs.hpp:71
cv::dnn::print
static void print(const MatShape &shape, const String &name="")
Definition: shape_utils.hpp:198
cv::Ptr
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
cv::imshow
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
cv::drawMatches
void drawMatches(InputArray img1, const std::vector< KeyPoint > &keypoints1, InputArray img2, const std::vector< KeyPoint > &keypoints2, const std::vector< std::vector< DMatch > > &matches1to2, InputOutputArray outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singlePointColor=Scalar::all(-1), const std::vector< std::vector< char > > &matchesMask=std::vector< std::vector< char > >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
features2d.hpp
cv::drawMatches
void drawMatches(InputArray img1, const std::vector< KeyPoint > &keypoints1, InputArray img2, const std::vector< KeyPoint > &keypoints2, const std::vector< DMatch > &matches1to2, InputOutputArray outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singlePointColor=Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
Draws the found matches of keypoints from two images.
cv::Mat
n-dimensional dense array class
Definition: mat.hpp:798
cv::imshow
void imshow(const String &winname, const ogl::Texture2D &tex)
Displays OpenGL 2D texture in the specified window.
cv::CommandLineParser
Designed for command line parsing.
Definition: utility.hpp:789
cv
"black box" representation of the file storage associated with a file on disk.
Definition: affine.hpp:52
cv::DescriptorMatcher::create
static Ptr< DescriptorMatcher > create(const String &descriptorMatcherType)
Creates a descriptor matcher of a given type with the default parameters (using default constructor).