2011-02-22 21:43:26 +01:00
Common Interfaces of Feature Detectors
======================================
2011-04-19 13:41:12 +02:00
.. highlight :: cpp
2011-05-04 21:22:51 +02:00
Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch
2011-02-26 12:05:10 +01:00
between different algorithms solving the same problem. All objects that implement keypoint detectors
2011-05-04 21:22:51 +02:00
inherit the
2011-06-23 14:00:09 +02:00
:ocv:class: `FeatureDetector` interface.
2011-02-22 21:43:26 +01:00
2013-08-06 16:24:09 +02:00
.. note ::
2013-07-29 15:51:16 +02:00
2013-08-06 16:24:09 +02:00
* An example explaining keypoint detection can be found at opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp
2011-04-19 13:41:12 +02:00
2011-02-22 21:43:26 +01:00
FeatureDetector
---------------
2012-05-28 09:36:14 +02:00
.. ocv:class :: FeatureDetector : public Algorithm
2011-02-22 21:43:26 +01:00
2011-06-23 14:00:09 +02:00
Abstract base class for 2D image feature detectors. ::
2011-02-22 21:43:26 +01:00
class CV_EXPORTS FeatureDetector
{
public:
virtual ~FeatureDetector();
2011-02-26 12:05:10 +01:00
2014-01-25 11:44:28 +01:00
void detect( InputArray image, vector<KeyPoint>& keypoints,
InputArray mask=noArray() ) const;
2011-02-26 12:05:10 +01:00
2014-01-25 11:44:28 +01:00
void detect( InputArrayOfArrays images,
2011-02-26 12:05:10 +01:00
vector<vector<KeyPoint> >& keypoints,
2014-01-25 11:44:28 +01:00
InputArrayOfArrays masks=noArray() ) const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
virtual void read(const FileNode&);
virtual void write(FileStorage&) const;
2011-02-26 12:05:10 +01:00
2013-03-22 17:51:45 +01:00
static Ptr<FeatureDetector> create( const String& detectorType );
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
protected:
...
};
2011-03-03 08:29:55 +01:00
2011-02-28 22:26:43 +01:00
FeatureDetector::detect
2011-02-22 21:43:26 +01:00
---------------------------
2011-06-30 00:06:42 +02:00
Detects keypoints in an image (first variant) or image set (second variant).
2011-02-22 21:43:26 +01:00
2014-01-25 11:44:28 +01:00
.. ocv:function :: void FeatureDetector::detect( InputArray image, vector<KeyPoint>& keypoints, InputArray mask=noArray() ) const
2011-02-22 21:43:26 +01:00
2014-01-25 11:44:28 +01:00
.. ocv:function :: void FeatureDetector::detect( InputArrayOfArrays images, vector<vector<KeyPoint> >& keypoints, InputArrayOfArrays masks=noArray() ) const
2011-02-22 21:43:26 +01:00
2013-07-11 06:03:32 +02:00
.. ocv:pyfunction :: cv2.FeatureDetector_create.detect(image[, mask]) -> keypoints
2011-07-22 14:50:49 +02:00
:param image: Image.
2011-02-22 21:43:26 +01:00
2011-05-04 21:22:51 +02:00
:param images: Image set.
2011-02-22 21:43:26 +01:00
2011-07-22 14:50:49 +02:00
:param keypoints: The detected keypoints. In the second variant of the method ``keypoints[i]`` is a set of keypoints detected in ``images[i]`` .
:param mask: Mask specifying where to look for keypoints (optional). It must be a 8-bit integer matrix with non-zero values in the region of interest.
2011-02-22 21:43:26 +01:00
2011-07-22 14:50:49 +02:00
:param masks: Masks for each input image specifying where to look for keypoints (optional). ``masks[i]`` is a mask for ``images[i]``.
2011-02-22 21:43:26 +01:00
2011-02-28 22:26:43 +01:00
FeatureDetector::create
2013-01-13 13:27:11 +01:00
-----------------------
2011-06-30 00:06:42 +02:00
Creates a feature detector by its name.
2011-02-22 21:43:26 +01:00
2013-03-22 17:51:45 +01:00
.. ocv:function :: Ptr<FeatureDetector> FeatureDetector::create( const String& detectorType )
2011-02-22 21:43:26 +01:00
2013-07-11 06:03:32 +02:00
.. ocv:pyfunction :: cv2.FeatureDetector_create(detectorType) -> retval
2011-02-26 12:05:10 +01:00
:param detectorType: Feature detector type.
2011-02-22 21:43:26 +01:00
2011-05-04 21:22:51 +02:00
The following detector types are supported:
2011-06-23 14:00:09 +02:00
* `` "FAST" `` -- :ocv:class: `FastFeatureDetector`
* `` "STAR" `` -- :ocv:class: `StarFeatureDetector`
2012-04-30 16:33:52 +02:00
* `` "ORB" `` -- :ocv:class: `ORB`
2013-02-03 14:31:15 +01:00
* `` "BRISK" `` -- :ocv:class: `BRISK`
2012-04-30 16:33:52 +02:00
* `` "MSER" `` -- :ocv:class: `MSER`
2011-08-13 18:49:40 +02:00
* `` "GFTT" `` -- :ocv:class: `GoodFeaturesToTrackDetector`
* `` "HARRIS" `` -- :ocv:class: `GoodFeaturesToTrackDetector` with Harris detector enabled
* `` "Dense" `` -- :ocv:class: `DenseFeatureDetector`
* `` "SimpleBlob" `` -- :ocv:class: `SimpleBlobDetector`
2011-05-04 21:22:51 +02:00
Also a combined format is supported: feature detector adapter name ( `` "Grid" `` --
2011-06-23 14:00:09 +02:00
:ocv:class: `GridAdaptedFeatureDetector` , `` "Pyramid" `` --
:ocv:class: `PyramidAdaptedFeatureDetector` ) + feature detector name (see above),
2011-05-08 17:30:00 +02:00
for example: `` "GridFAST" `` , `` "PyramidSTAR" `` .
2011-02-22 21:43:26 +01:00
FastFeatureDetector
-------------------
2012-05-28 09:36:14 +02:00
.. ocv:class :: FastFeatureDetector : public FeatureDetector
2011-02-22 21:43:26 +01:00
2011-05-04 21:22:51 +02:00
Wrapping class for feature detection using the
2011-06-23 14:00:09 +02:00
:ocv:func: `FAST` method. ::
2011-02-22 21:43:26 +01:00
class FastFeatureDetector : public FeatureDetector
{
public:
2012-08-07 16:17:30 +02:00
FastFeatureDetector( int threshold=1, bool nonmaxSuppression=true, type=FastFeatureDetector::TYPE_9_16 );
2011-02-22 21:43:26 +01:00
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
};
2011-03-03 08:29:55 +01:00
2011-02-22 21:43:26 +01:00
GoodFeaturesToTrackDetector
---------------------------
2012-05-28 16:36:15 +02:00
.. ocv:class :: GoodFeaturesToTrackDetector : public FeatureDetector
2011-02-22 21:43:26 +01:00
2011-05-04 21:22:51 +02:00
Wrapping class for feature detection using the
2011-06-23 14:00:09 +02:00
:ocv:func: `goodFeaturesToTrack` function. ::
2011-02-22 21:43:26 +01:00
class GoodFeaturesToTrackDetector : public FeatureDetector
{
public:
class Params
{
public:
2011-02-26 12:05:10 +01:00
Params( int maxCorners=1000, double qualityLevel=0.01,
double minDistance=1., int blockSize=3,
2011-02-22 21:43:26 +01:00
bool useHarrisDetector=false, double k=0.04 );
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
int maxCorners;
double qualityLevel;
double minDistance;
int blockSize;
bool useHarrisDetector;
double k;
};
2011-02-26 12:05:10 +01:00
2011-02-22 21:43:26 +01:00
GoodFeaturesToTrackDetector( const GoodFeaturesToTrackDetector::Params& params=
GoodFeaturesToTrackDetector::Params() );
2011-02-26 12:05:10 +01:00
GoodFeaturesToTrackDetector( int maxCorners, double qualityLevel,
double minDistance, int blockSize=3,
2011-02-22 21:43:26 +01:00
bool useHarrisDetector=false, double k=0.04 );
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
};
2011-03-03 08:29:55 +01:00
2011-02-22 21:43:26 +01:00
MserFeatureDetector
-------------------
2012-05-28 16:36:15 +02:00
.. ocv:class :: MserFeatureDetector : public FeatureDetector
2011-02-22 21:43:26 +01:00
2011-05-04 21:22:51 +02:00
Wrapping class for feature detection using the
2011-06-23 14:00:09 +02:00
:ocv:class: `MSER` class. ::
2011-02-22 21:43:26 +01:00
class MserFeatureDetector : public FeatureDetector
{
public:
MserFeatureDetector( CvMSERParams params=cvMSERParams() );
2011-02-26 12:05:10 +01:00
MserFeatureDetector( int delta, int minArea, int maxArea,
2011-02-22 21:43:26 +01:00
double maxVariation, double minDiversity,
2011-02-26 12:05:10 +01:00
int maxEvolution, double areaThreshold,
2011-02-22 21:43:26 +01:00
double minMargin, int edgeBlurSize );
virtual void read( const FileNode& fn );
virtual void write( FileStorage& fs ) const;
protected:
...
};
2011-03-03 08:29:55 +01:00
2011-06-09 17:20:55 +02:00
SimpleBlobDetector
-------------------
2012-05-28 09:36:14 +02:00
.. ocv:class :: SimpleBlobDetector : public FeatureDetector
2011-06-09 17:20:55 +02:00
2011-06-23 14:00:09 +02:00
Class for extracting blobs from an image. ::
2011-06-09 17:20:55 +02:00
class SimpleBlobDetector : public FeatureDetector
{
public:
struct Params
{
Params();
float thresholdStep;
float minThreshold;
float maxThreshold;
size_t minRepeatability;
float minDistBetweenBlobs;
bool filterByColor;
uchar blobColor;
bool filterByArea;
float minArea, maxArea;
bool filterByCircularity;
float minCircularity, maxCircularity;
bool filterByInertia;
float minInertiaRatio, maxInertiaRatio;
bool filterByConvexity;
float minConvexity, maxConvexity;
};
SimpleBlobDetector(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
protected:
...
};
2011-06-23 14:00:09 +02:00
The class implements a simple algorithm for extracting blobs from an image:
2012-03-29 10:07:57 +02:00
#. Convert the source image to binary images by applying thresholding with several thresholds from `` minThreshold `` (inclusive) to `` maxThreshold `` (exclusive) with distance `` thresholdStep `` between neighboring thresholds.
2011-06-23 14:00:09 +02:00
2012-03-29 10:07:57 +02:00
#. Extract connected components from every binary image by :ocv:func: `findContours` and calculate their centers.
2011-06-23 14:00:09 +02:00
2012-03-29 10:07:57 +02:00
#. Group centers from several binary images by their coordinates. Close centers form one group that corresponds to one blob, which is controlled by the `` minDistBetweenBlobs `` parameter.
2011-06-23 14:00:09 +02:00
#. From the groups, estimate final centers of blobs and their radiuses and return as locations and sizes of keypoints.
2011-06-09 17:20:55 +02:00
This class performs several filtrations of returned blobs. You should set `` filterBy* `` to true/false to turn on/off corresponding filtration. Available filtrations:
2011-06-23 14:00:09 +02:00
* **By color** . This filter compares the intensity of a binary image at the center of a blob to `` blobColor `` . If they differ, the blob is filtered out. Use `` blobColor = 0 `` to extract dark blobs and `` blobColor = 255 `` to extract light blobs.
2011-06-09 17:20:55 +02:00
2011-06-23 14:00:09 +02:00
* **By area** . Extracted blobs have an area between `` minArea `` (inclusive) and `` maxArea `` (exclusive).
2011-06-09 17:20:55 +02:00
2011-06-23 14:00:09 +02:00
* **By circularity** . Extracted blobs have circularity (:math: `\frac{4*\pi*Area}{perimeter * perimeter}` ) between `` minCircularity `` (inclusive) and `` maxCircularity `` (exclusive).
2011-06-09 17:20:55 +02:00
2011-06-23 14:00:09 +02:00
* **By ratio of the minimum inertia to maximum inertia** . Extracted blobs have this ratio between `` minInertiaRatio `` (inclusive) and `` maxInertiaRatio `` (exclusive).
2011-06-09 17:20:55 +02:00
2011-06-23 14:00:09 +02:00
* **By convexity** . Extracted blobs have convexity (area / area of blob convex hull) between `` minConvexity `` (inclusive) and `` maxConvexity `` (exclusive).
2011-06-09 17:20:55 +02:00
Default values of parameters are tuned to extract dark circular blobs.