OpenCV  4.5.2
Open Source Computer Vision
Feature Detection

Table of Contents

Prev Tutorial: Detecting corners location in subpixels
Next Tutorial: Feature Description

Original author Ana Huamán
Compatibility OpenCV >= 3.0

Goal

In this tutorial you will learn how to:

Warning
You need the OpenCV contrib modules to be able to use the SURF features (alternatives are ORB, KAZE, ... features).

Theory

Code

Explanation

Result

  1. Here is the result of the feature detection applied to the box.png image:

  2. And here is the result for the box_in_scene.png image:

cv::xfeatures2d
Definition: nonfree.hpp:50
cv::String
std::string String
Definition: cvstd.hpp:150
cv::samples::findFile
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
cv::waitKey
int waitKey(int delay=0)
Waits for a pressed key.
highgui.hpp
core.hpp
cv::imread
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
cv::Mat::empty
bool empty() const
Returns true if the array has no elements.
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::xfeatures2d::SURF::create
static Ptr< SURF > create(double hessianThreshold=100, int nOctaves=4, int nOctaveLayers=3, bool extended=false, bool upright=false)
features2d.hpp
cv::Mat
n-dimensional dense array class
Definition: mat.hpp:801
cv::imshow
void imshow(const String &winname, const ogl::Texture2D &tex)
Displays OpenGL 2D texture in the specified window.
cv::drawKeypoints
void drawKeypoints(InputArray image, const std::vector< KeyPoint > &keypoints, InputOutputArray outImage, const Scalar &color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
Draws keypoints.
cv::CommandLineParser
Designed for command line parsing.
Definition: utility.hpp:799
cv
"black box" representation of the file storage associated with a file on disk.
Definition: affine.hpp:51
cv::Feature2D::detect
virtual void detect(InputArray image, std::vector< KeyPoint > &keypoints, InputArray mask=noArray())
Detects keypoints in an image (first variant) or image set (second variant).
xfeatures2d.hpp