|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#ifndef __OPENCV_FEATURES_2D_HPP__
|
|
|
|
#define __OPENCV_FEATURES_2D_HPP__
|
|
|
|
|
|
|
|
#include "opencv2/core.hpp"
|
|
|
|
#include "opencv2/flann/miniflann.hpp"
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
|
|
|
|
// //! writes vector of keypoints to the file storage
|
|
|
|
// CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector<KeyPoint>& keypoints);
|
|
|
|
// //! reads vector of keypoints from the specified file storage node
|
|
|
|
// CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector<KeyPoint>& keypoints);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class filters a vector of keypoints.
|
|
|
|
* Because now it is difficult to provide a convenient interface for all usage scenarios of the keypoints filter class,
|
|
|
|
* it has only several needed by now static methods.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS KeyPointsFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KeyPointsFilter(){}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove keypoints within borderPixels of an image edge.
|
|
|
|
*/
|
|
|
|
static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize );
|
|
|
|
/*
|
|
|
|
* Remove keypoints of sizes out of range.
|
|
|
|
*/
|
|
|
|
static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize,
|
|
|
|
float maxSize=FLT_MAX );
|
|
|
|
/*
|
|
|
|
* Remove keypoints from some image by mask for pixels of this image.
|
|
|
|
*/
|
|
|
|
static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask );
|
|
|
|
/*
|
|
|
|
* Remove duplicated keypoints.
|
|
|
|
*/
|
|
|
|
static void removeDuplicated( std::vector<KeyPoint>& keypoints );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retain the specified number of the best keypoints (according to the response)
|
|
|
|
*/
|
|
|
|
static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/************************************ Base Classes ************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abstract base class for 2D image feature detectors and descriptor extractors
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W Feature2D : public virtual Algorithm
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Feature2D();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect keypoints in an image.
|
|
|
|
* image The image.
|
|
|
|
* keypoints The detected keypoints.
|
|
|
|
* mask Mask specifying where to look for keypoints (optional). Must be a char
|
|
|
|
* matrix with non-zero values in the region of interest.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual void detect( InputArray image,
|
|
|
|
CV_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
InputArray mask=noArray() );
|
|
|
|
|
|
|
|
virtual void detect( InputArrayOfArrays images,
|
|
|
|
std::vector<std::vector<KeyPoint> >& keypoints,
|
|
|
|
InputArrayOfArrays masks=noArray() );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the descriptors for a set of keypoints in an image.
|
|
|
|
* image The image.
|
|
|
|
* keypoints The input keypoints. Keypoints for which a descriptor cannot be computed are removed.
|
|
|
|
* descriptors Copmputed descriptors. Row i is the descriptor for keypoint i.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual void compute( InputArray image,
|
|
|
|
CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
OutputArray descriptors );
|
|
|
|
|
|
|
|
virtual void compute( InputArrayOfArrays images,
|
|
|
|
std::vector<std::vector<KeyPoint> >& keypoints,
|
|
|
|
OutputArrayOfArrays descriptors );
|
|
|
|
|
|
|
|
/* Detects keypoints and computes the descriptors */
|
|
|
|
CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask,
|
|
|
|
CV_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
OutputArray descriptors,
|
|
|
|
bool useProvidedKeypoints=false );
|
|
|
|
|
|
|
|
CV_WRAP virtual int descriptorSize() const;
|
|
|
|
CV_WRAP virtual int descriptorType() const;
|
|
|
|
CV_WRAP virtual int defaultNorm() const;
|
|
|
|
|
|
|
|
// Return true if detector object is empty
|
|
|
|
CV_WRAP virtual bool empty() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Feature2D FeatureDetector;
|
|
|
|
typedef Feature2D DescriptorExtractor;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
BRISK implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BRISK : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f);
|
|
|
|
// custom setup
|
|
|
|
CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList,
|
|
|
|
float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>());
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
ORB implementation.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W ORB : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// the size of the signature in bytes
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1,
|
|
|
|
NFEATURES=10000, SCALE_FACTOR=10001, NLEVELS=10002,
|
|
|
|
EDGE_THRESHOLD=10003, FIRST_LEVEL=10004, WTA_K=10005,
|
|
|
|
SCORE_TYPE=10006, PATCH_SIZE=10007, FAST_THRESHOLD=10008
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<ORB> create(int nfeatures = 500, float scaleFactor = 1.2f, int nlevels = 8, int edgeThreshold = 31,
|
|
|
|
int firstLevel = 0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold = 20);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Maximal Stable Extremal Regions class.
|
|
|
|
|
|
|
|
The class implements MSER algorithm introduced by J. Matas.
|
|
|
|
Unlike SIFT, SURF and many other detectors in OpenCV, this is salient region detector,
|
|
|
|
not the salient point detector.
|
|
|
|
|
|
|
|
It returns the regions, each of those is encoded as a contour.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W MSER : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DELTA=10000, MIN_AREA=10001, MAX_AREA=10002, PASS2_ONLY=10003,
|
|
|
|
MAX_EVOLUTION=10004, AREA_THRESHOLD=10005,
|
|
|
|
MIN_MARGIN=10006, EDGE_BLUR_SIZE=10007
|
|
|
|
};
|
|
|
|
|
|
|
|
//! the full constructor
|
|
|
|
CV_WRAP static Ptr<MSER> create( int _delta=5, int _min_area=60, int _max_area=14400,
|
|
|
|
double _max_variation=0.25, double _min_diversity=.2,
|
|
|
|
int _max_evolution=200, double _area_threshold=1.01,
|
|
|
|
double _min_margin=0.003, int _edge_blur_size=5 );
|
|
|
|
|
|
|
|
CV_WRAP virtual void detectRegions( InputArray image,
|
|
|
|
std::vector<std::vector<Point> >& msers,
|
|
|
|
std::vector<Rect>& bboxes ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! detects corners using FAST algorithm by E. Rosten
|
|
|
|
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
int threshold, bool nonmaxSuppression=true );
|
|
|
|
|
|
|
|
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
int threshold, bool nonmaxSuppression, int type );
|
|
|
|
|
|
|
|
class CV_EXPORTS_W FastFeatureDetector : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2,
|
|
|
|
THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002,
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10,
|
|
|
|
bool nonmaxSuppression=true,
|
|
|
|
int type=FastFeatureDetector::TYPE_9_16 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CV_EXPORTS_W GFTTDetector : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { USE_HARRIS_DETECTOR=10000 };
|
|
|
|
CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
|
|
|
|
int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct CV_EXPORTS_W_SIMPLE Params
|
|
|
|
{
|
|
|
|
CV_WRAP Params();
|
|
|
|
CV_PROP_RW float thresholdStep;
|
|
|
|
CV_PROP_RW float minThreshold;
|
|
|
|
CV_PROP_RW float maxThreshold;
|
|
|
|
CV_PROP_RW size_t minRepeatability;
|
|
|
|
CV_PROP_RW float minDistBetweenBlobs;
|
|
|
|
|
|
|
|
CV_PROP_RW bool filterByColor;
|
|
|
|
CV_PROP_RW uchar blobColor;
|
|
|
|
|
|
|
|
CV_PROP_RW bool filterByArea;
|
|
|
|
CV_PROP_RW float minArea, maxArea;
|
|
|
|
|
|
|
|
CV_PROP_RW bool filterByCircularity;
|
|
|
|
CV_PROP_RW float minCircularity, maxCircularity;
|
|
|
|
|
|
|
|
CV_PROP_RW bool filterByInertia;
|
|
|
|
CV_PROP_RW float minInertiaRatio, maxInertiaRatio;
|
|
|
|
|
|
|
|
CV_PROP_RW bool filterByConvexity;
|
|
|
|
CV_PROP_RW float minConvexity, maxConvexity;
|
|
|
|
|
|
|
|
void read( const FileNode& fn );
|
|
|
|
void write( FileStorage& fs ) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<SimpleBlobDetector>
|
|
|
|
create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
KAZE implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W KAZE : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DIFF_PM_G1 = 0,
|
|
|
|
DIFF_PM_G2 = 1,
|
|
|
|
DIFF_WEICKERT = 2,
|
|
|
|
DIFF_CHARBONNIER = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<KAZE> create(bool extended=false, bool upright=false,
|
|
|
|
float threshold = 0.001f,
|
|
|
|
int octaves = 4, int sublevels = 4,
|
|
|
|
int diffusivity = KAZE::DIFF_PM_G2);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
AKAZE implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W AKAZE : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// AKAZE descriptor type
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
|
|
|
|
DESCRIPTOR_KAZE = 3,
|
|
|
|
DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
|
|
|
|
DESCRIPTOR_MLDB = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<AKAZE> create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB,
|
|
|
|
int descriptor_size = 0, int descriptor_channels = 3,
|
|
|
|
float threshold = 0.001f, int octaves = 4,
|
|
|
|
int sublevels = 4, int diffusivity = KAZE::DIFF_PM_G2);
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Distance *
|
|
|
|
\****************************************************************************************/
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct CV_EXPORTS Accumulator
|
|
|
|
{
|
|
|
|
typedef T Type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> struct Accumulator<unsigned char> { typedef float Type; };
|
|
|
|
template<> struct Accumulator<unsigned short> { typedef float Type; };
|
|
|
|
template<> struct Accumulator<char> { typedef float Type; };
|
|
|
|
template<> struct Accumulator<short> { typedef float Type; };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Squared Euclidean distance functor
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS SL2
|
|
|
|
{
|
|
|
|
enum { normType = NORM_L2SQR };
|
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
|
|
|
|
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
|
|
|
return normL2Sqr<ValueType, ResultType>(a, b, size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Euclidean distance functor
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS L2
|
|
|
|
{
|
|
|
|
enum { normType = NORM_L2 };
|
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
|
|
|
|
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
|
|
|
return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manhattan distance (city block distance) functor
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS L1
|
|
|
|
{
|
|
|
|
enum { normType = NORM_L1 };
|
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
|
|
|
|
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
|
|
|
return normL1<ValueType, ResultType>(a, b, size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
|
|
|
* bit count of A exclusive XOR'ed with B
|
|
|
|
*/
|
|
|
|
struct CV_EXPORTS Hamming
|
|
|
|
{
|
|
|
|
enum { normType = NORM_HAMMING };
|
|
|
|
typedef unsigned char ValueType;
|
|
|
|
typedef int ResultType;
|
|
|
|
|
|
|
|
/** this will count the bits in a ^ b
|
|
|
|
*/
|
|
|
|
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
|
|
|
{
|
|
|
|
return normHamming(a, b, size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Hamming HammingLUT;
|
|
|
|
|
|
|
|
template<int cellsize> struct HammingMultilevel
|
|
|
|
{
|
|
|
|
enum { normType = NORM_HAMMING + (cellsize>1) };
|
|
|
|
typedef unsigned char ValueType;
|
|
|
|
typedef int ResultType;
|
|
|
|
|
|
|
|
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
|
|
|
{
|
|
|
|
return normHamming(a, b, size, cellsize);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* DescriptorMatcher *
|
|
|
|
\****************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Abstract base class for matching two sets of descriptors.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W DescriptorMatcher : public Algorithm
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~DescriptorMatcher();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add descriptors to train descriptor collection.
|
|
|
|
* descriptors Descriptors to add. Each descriptors[i] is a descriptors set from one image.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual void add( InputArrayOfArrays descriptors );
|
|
|
|
/*
|
|
|
|
* Get train descriptors collection.
|
|
|
|
*/
|
|
|
|
CV_WRAP const std::vector<Mat>& getTrainDescriptors() const;
|
|
|
|
/*
|
|
|
|
* Clear train descriptors collection.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual void clear();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if there are not train descriptors in collection.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual bool empty() const;
|
|
|
|
/*
|
|
|
|
* Return true if the matcher supports mask in match methods.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual bool isMaskSupported() const = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Train matcher (e.g. train flann index).
|
|
|
|
* In all methods to match the method train() is run every time before matching.
|
|
|
|
* Some descriptor matchers (e.g. BruteForceMatcher) have empty implementation
|
|
|
|
* of this method, other matchers really train their inner structures
|
|
|
|
* (e.g. FlannBasedMatcher trains flann::Index). So nonempty implementation
|
|
|
|
* of train() should check the class object state and do traing/retraining
|
|
|
|
* only if the state requires that (e.g. FlannBasedMatcher trains flann::Index
|
|
|
|
* if it has not trained yet or if new descriptors have been added to the train
|
|
|
|
* collection).
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual void train();
|
|
|
|
/*
|
|
|
|
* Group of methods to match descriptors from image pair.
|
|
|
|
* Method train() is run in this methods.
|
|
|
|
*/
|
|
|
|
// Find one best match for each query descriptor (if mask is empty).
|
|
|
|
CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors,
|
|
|
|
CV_OUT std::vector<DMatch>& matches, InputArray mask=noArray() ) const;
|
|
|
|
// Find k best matches for each query descriptor (in increasing order of distances).
|
|
|
|
// compactResult is used when mask is not empty. If compactResult is false matches
|
|
|
|
// vector will have the same size as queryDescriptors rows. If compactResult is true
|
|
|
|
// matches vector will not contain matches for fully masked out query descriptors.
|
|
|
|
CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
|
|
|
CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
InputArray mask=noArray(), bool compactResult=false ) const;
|
|
|
|
// Find best matches for each query descriptor which have distance less than
|
|
|
|
// maxDistance (in increasing order of distances).
|
|
|
|
void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
InputArray mask=noArray(), bool compactResult=false ) const;
|
|
|
|
/*
|
|
|
|
* Group of methods to match descriptors from one image to image set.
|
|
|
|
* See description of similar methods for matching image pair above.
|
|
|
|
*/
|
|
|
|
CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector<DMatch>& matches,
|
|
|
|
InputArrayOfArrays masks=noArray() );
|
|
|
|
CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
|
|
|
|
// Reads matcher object from a file node
|
|
|
|
virtual void read( const FileNode& );
|
|
|
|
// Writes matcher object to a file storage
|
|
|
|
virtual void write( FileStorage& ) const;
|
|
|
|
|
|
|
|
// Clone the matcher. If emptyTrainData is false the method create deep copy of the object, i.e. copies
|
|
|
|
// both parameters and train data. If emptyTrainData is true the method create object copy with current parameters
|
|
|
|
// but with empty train data.
|
|
|
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
|
|
|
|
|
|
|
|
CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType );
|
|
|
|
protected:
|
|
|
|
/*
|
|
|
|
* Class to work with descriptors from several images as with one merged matrix.
|
|
|
|
* It is used e.g. in FlannBasedMatcher.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS DescriptorCollection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DescriptorCollection();
|
|
|
|
DescriptorCollection( const DescriptorCollection& collection );
|
|
|
|
virtual ~DescriptorCollection();
|
|
|
|
|
|
|
|
// Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here.
|
|
|
|
void set( const std::vector<Mat>& descriptors );
|
|
|
|
virtual void clear();
|
|
|
|
|
|
|
|
const Mat& getDescriptors() const;
|
|
|
|
const Mat getDescriptor( int imgIdx, int localDescIdx ) const;
|
|
|
|
const Mat getDescriptor( int globalDescIdx ) const;
|
|
|
|
void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const;
|
|
|
|
|
|
|
|
int size() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Mat mergedDescriptors;
|
|
|
|
std::vector<int> startIdxs;
|
|
|
|
};
|
|
|
|
|
|
|
|
// In fact the matching is implemented only by the following two methods. These methods suppose
|
|
|
|
// that the class object has been trained already. Public match methods call these methods
|
|
|
|
// after calling train().
|
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
|
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
|
|
|
|
|
|
|
|
static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx );
|
|
|
|
static bool isMaskedOut( InputArrayOfArrays masks, int queryIdx );
|
|
|
|
|
|
|
|
static Mat clone_op( Mat m ) { return m.clone(); }
|
|
|
|
void checkMasks( InputArrayOfArrays masks, int queryDescriptorsCount ) const;
|
|
|
|
|
|
|
|
// Collection of descriptors from train images.
|
|
|
|
std::vector<Mat> trainDescCollection;
|
|
|
|
std::vector<UMat> utrainDescCollection;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Brute-force descriptor matcher.
|
|
|
|
*
|
|
|
|
* For each descriptor in the first set, this matcher finds the closest
|
|
|
|
* descriptor in the second set by trying each one.
|
|
|
|
*
|
|
|
|
* For efficiency, BruteForceMatcher is templated on the distance metric.
|
|
|
|
* For float descriptors, a common choice would be cv::L2<float>.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false );
|
|
|
|
virtual ~BFMatcher() {}
|
|
|
|
|
|
|
|
virtual bool isMaskSupported() const { return true; }
|
|
|
|
|
|
|
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
|
|
|
protected:
|
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
|
|
|
|
int normType;
|
|
|
|
bool crossCheck;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flann based matcher
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
|
|
|
|
const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
|
|
|
|
|
|
|
|
virtual void add( InputArrayOfArrays descriptors );
|
|
|
|
virtual void clear();
|
|
|
|
|
|
|
|
// Reads matcher object from a file node
|
|
|
|
virtual void read( const FileNode& );
|
|
|
|
// Writes matcher object to a file storage
|
|
|
|
virtual void write( FileStorage& ) const;
|
|
|
|
|
|
|
|
virtual void train();
|
|
|
|
virtual bool isMaskSupported() const;
|
|
|
|
|
|
|
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
|
|
|
protected:
|
|
|
|
static void convertToDMatches( const DescriptorCollection& descriptors,
|
|
|
|
const Mat& indices, const Mat& distances,
|
|
|
|
std::vector<std::vector<DMatch> >& matches );
|
|
|
|
|
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
|
|
|
|
|
|
|
Ptr<flann::IndexParams> indexParams;
|
|
|
|
Ptr<flann::SearchParams> searchParams;
|
|
|
|
Ptr<flann::Index> flannIndex;
|
|
|
|
|
|
|
|
DescriptorCollection mergedDescriptors;
|
|
|
|
int addedDescCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Drawing functions *
|
|
|
|
\****************************************************************************************/
|
|
|
|
struct CV_EXPORTS DrawMatchesFlags
|
|
|
|
{
|
|
|
|
enum{ DEFAULT = 0, // Output image matrix will be created (Mat::create),
|
|
|
|
// i.e. existing memory of output image may be reused.
|
|
|
|
// Two source image, matches and single keypoints will be drawn.
|
|
|
|
// For each keypoint only the center point will be drawn (without
|
|
|
|
// the circle around keypoint with keypoint size and orientation).
|
|
|
|
DRAW_OVER_OUTIMG = 1, // Output image matrix will not be created (Mat::create).
|
|
|
|
// Matches will be drawn on existing content of output image.
|
|
|
|
NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.
|
|
|
|
DRAW_RICH_KEYPOINTS = 4 // For each keypoint the circle around keypoint with keypoint size and
|
|
|
|
// orientation will be drawn.
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw keypoints.
|
|
|
|
CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,
|
|
|
|
const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT );
|
|
|
|
|
|
|
|
// Draws matches of keypints from two images on output image.
|
|
|
|
CV_EXPORTS_W 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>(), int flags=DrawMatchesFlags::DEFAULT );
|
|
|
|
|
|
|
|
CV_EXPORTS_AS(drawMatchesKnn) 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> >(), int flags=DrawMatchesFlags::DEFAULT );
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Functions to evaluate the feature detectors and [generic] descriptor extractors *
|
|
|
|
\****************************************************************************************/
|
|
|
|
|
|
|
|
CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2,
|
|
|
|
std::vector<KeyPoint>* keypoints1, std::vector<KeyPoint>* keypoints2,
|
|
|
|
float& repeatability, int& correspCount,
|
|
|
|
const Ptr<FeatureDetector>& fdetector=Ptr<FeatureDetector>() );
|
|
|
|
|
|
|
|
CV_EXPORTS void computeRecallPrecisionCurve( const std::vector<std::vector<DMatch> >& matches1to2,
|
|
|
|
const std::vector<std::vector<uchar> >& correctMatches1to2Mask,
|
|
|
|
std::vector<Point2f>& recallPrecisionCurve );
|
|
|
|
|
|
|
|
CV_EXPORTS float getRecall( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
|
|
|
|
CV_EXPORTS int getNearestPoint( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Bag of visual words *
|
|
|
|
\****************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Abstract base class for training of a 'bag of visual words' vocabulary from a set of descriptors
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BOWTrainer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BOWTrainer();
|
|
|
|
virtual ~BOWTrainer();
|
|
|
|
|
|
|
|
CV_WRAP void add( const Mat& descriptors );
|
|
|
|
CV_WRAP const std::vector<Mat>& getDescriptors() const;
|
|
|
|
CV_WRAP int descriptorsCount() const;
|
|
|
|
|
|
|
|
CV_WRAP virtual void clear();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Train visual words vocabulary, that is cluster training descriptors and
|
|
|
|
* compute cluster centers.
|
|
|
|
* Returns cluster centers.
|
|
|
|
*
|
|
|
|
* descriptors Training descriptors computed on images keypoints.
|
|
|
|
*/
|
|
|
|
CV_WRAP virtual Mat cluster() const = 0;
|
|
|
|
CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<Mat> descriptors;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is BOWTrainer using cv::kmeans to get vocabulary.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
|
|
|
|
int attempts=3, int flags=KMEANS_PP_CENTERS );
|
|
|
|
virtual ~BOWKMeansTrainer();
|
|
|
|
|
|
|
|
// Returns trained vocabulary (i.e. cluster centers).
|
|
|
|
CV_WRAP virtual Mat cluster() const;
|
|
|
|
CV_WRAP virtual Mat cluster( const Mat& descriptors ) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int clusterCount;
|
|
|
|
TermCriteria termcrit;
|
|
|
|
int attempts;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class to compute image descriptor using bag of visual words.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BOWImgDescriptorExtractor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
|
|
|
const Ptr<DescriptorMatcher>& dmatcher );
|
|
|
|
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
|
|
|
|
virtual ~BOWImgDescriptorExtractor();
|
|
|
|
|
|
|
|
CV_WRAP void setVocabulary( const Mat& vocabulary );
|
|
|
|
CV_WRAP const Mat& getVocabulary() const;
|
|
|
|
void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray imgDescriptor,
|
|
|
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
|
|
|
|
void compute( InputArray keypointDescriptors, OutputArray imgDescriptor,
|
|
|
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
|
|
|
|
// compute() is not constant because DescriptorMatcher::match is not constant
|
|
|
|
|
|
|
|
CV_WRAP_AS(compute) void compute2( const Mat& image, std::vector<KeyPoint>& keypoints, CV_OUT Mat& imgDescriptor )
|
|
|
|
{ compute(image,keypoints,imgDescriptor); }
|
|
|
|
|
|
|
|
CV_WRAP int descriptorSize() const;
|
|
|
|
CV_WRAP int descriptorType() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Mat vocabulary;
|
|
|
|
Ptr<DescriptorExtractor> dextractor;
|
|
|
|
Ptr<DescriptorMatcher> dmatcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace cv */
|
|
|
|
|
|
|
|
#endif
|