2010-05-12 01:44:00 +08:00
|
|
|
/*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__
|
|
|
|
|
2013-03-29 16:59:55 +08:00
|
|
|
#include "opencv2/core.hpp"
|
2013-04-08 04:24:39 +08:00
|
|
|
#include "opencv2/flann/miniflann.hpp"
|
2010-05-12 15:33:21 +08:00
|
|
|
|
2010-05-26 20:34:48 +08:00
|
|
|
namespace cv
|
|
|
|
{
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
CV_EXPORTS bool initModule_features2d();
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-03-26 18:58:09 +08:00
|
|
|
// //! 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);
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2011-05-02 01:38:52 +08:00
|
|
|
/*
|
|
|
|
* 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,
|
2012-07-13 01:51:12 +08:00
|
|
|
* it has only several needed by now static methods.
|
2011-05-02 01:38:52 +08:00
|
|
|
*/
|
|
|
|
class CV_EXPORTS KeyPointsFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KeyPointsFilter(){}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove keypoints within borderPixels of an image edge.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize );
|
2011-05-02 01:38:52 +08:00
|
|
|
/*
|
|
|
|
* Remove keypoints of sizes out of range.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize,
|
2012-03-15 22:36:01 +08:00
|
|
|
float maxSize=FLT_MAX );
|
2011-05-05 18:10:46 +08:00
|
|
|
/*
|
|
|
|
* Remove keypoints from some image by mask for pixels of this image.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask );
|
2011-06-01 02:18:02 +08:00
|
|
|
/*
|
|
|
|
* Remove duplicated keypoints.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void removeDuplicated( std::vector<KeyPoint>& keypoints );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* Retain the specified number of the best keypoints (according to the response)
|
2011-05-21 06:25:53 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/************************************ Base Classes ************************************/
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Abstract base class for 2D image feature detectors.
|
|
|
|
*/
|
2012-03-15 22:36:01 +08:00
|
|
|
class CV_EXPORTS_W FeatureDetector : public virtual Algorithm
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual ~FeatureDetector();
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
/*
|
2010-11-23 02:27:08 +08:00
|
|
|
* Detect keypoints in an image.
|
2010-05-12 01:44:00 +08:00
|
|
|
* image The image.
|
|
|
|
* keypoints The detected keypoints.
|
2010-07-26 16:58:46 +08:00
|
|
|
* mask Mask specifying where to look for keypoints (optional). Must be a char
|
|
|
|
* matrix with non-zero values in the region of interest.
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
|
|
|
* Detect keypoints in an image set.
|
2010-11-23 02:27:08 +08:00
|
|
|
* images Image collection.
|
|
|
|
* keypoints Collection of keypoints detected in an input images. keypoints[i] is a set of keypoints detected in an images[i].
|
|
|
|
* masks Masks for image set. masks[i] is a mask for images[i].
|
2010-10-29 16:44:42 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyPoint> >& keypoints, const std::vector<Mat>& masks=std::vector<Mat>() ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2011-01-31 22:18:50 +08:00
|
|
|
// Return true if detector object is empty
|
2011-09-07 17:38:22 +08:00
|
|
|
CV_WRAP virtual bool empty() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-11-25 23:59:37 +08:00
|
|
|
// Create feature detector by detector name.
|
2013-03-23 00:37:49 +08:00
|
|
|
CV_WRAP static Ptr<FeatureDetector> create( const String& detectorType );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const = 0;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2011-05-11 20:59:36 +08:00
|
|
|
/*
|
|
|
|
* Remove keypoints that are not in the mask.
|
|
|
|
* Helper function, useful when wrapping a library call for keypoint detection that
|
|
|
|
* does not support a mask argument.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void removeInvalidPoints( const Mat& mask, std::vector<KeyPoint>& keypoints );
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* Abstract base class for computing descriptors for image keypoints.
|
|
|
|
*
|
|
|
|
* In this interface we assume a keypoint descriptor can be represented as a
|
|
|
|
* dense, fixed-dimensional vector of some basic type. Most descriptors used
|
|
|
|
* in practice follow this pattern, as it makes it very easy to compute
|
|
|
|
* distances between descriptors. Therefore we represent a collection of
|
|
|
|
* descriptors as a Mat, where each row is one keypoint descriptor.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W DescriptorExtractor : public virtual Algorithm
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
virtual ~DescriptorExtractor();
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints, CV_OUT Mat& descriptors ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* Compute the descriptors for a keypoints collection detected in image collection.
|
|
|
|
* images Image collection.
|
|
|
|
* keypoints Input keypoints collection. keypoints[i] is keypoints detected in images[i].
|
|
|
|
* Keypoints for which a descriptor cannot be computed are removed.
|
|
|
|
* descriptors Descriptor collection. descriptors[i] are descriptors computed for set keypoints[i].
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyPoint> >& keypoints, std::vector<Mat>& descriptors ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
CV_WRAP virtual int descriptorSize() const = 0;
|
|
|
|
CV_WRAP virtual int descriptorType() const = 0;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
CV_WRAP virtual bool empty() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
CV_WRAP static Ptr<DescriptorExtractor> create( const String& descriptorExtractorType );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const = 0;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* Remove keypoints within borderPixels of an image edge.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
static void removeBorderKeypoints( std::vector<KeyPoint>& keypoints,
|
2012-03-15 22:36:01 +08:00
|
|
|
Size imageSize, int borderSize );
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* Abstract base class for simultaneous 2D feature detection descriptor extraction.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W Feature2D : public FeatureDetector, public DescriptorExtractor
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
* useProvidedKeypoints If true, the method will skip the detection phase and will compute
|
2012-05-29 18:36:19 +08:00
|
|
|
* descriptors for the provided keypoints
|
2012-03-15 22:36:01 +08:00
|
|
|
*/
|
|
|
|
CV_WRAP_AS(detectAndCompute) virtual void operator()( InputArray image, InputArray mask,
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_OUT std::vector<KeyPoint>& keypoints,
|
2012-03-15 22:36:01 +08:00
|
|
|
OutputArray descriptors,
|
|
|
|
bool useProvidedKeypoints=false ) const = 0;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
// Create feature detector and descriptor extractor by name.
|
2013-03-23 00:37:49 +08:00
|
|
|
CV_WRAP static Ptr<Feature2D> create( const String& name );
|
2012-03-15 22:36:01 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-08-23 20:52:01 +08:00
|
|
|
/*!
|
|
|
|
BRISK implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W BRISK : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_WRAP explicit BRISK(int thresh=30, int octaves=3, float patternScale=1.0f);
|
|
|
|
|
|
|
|
virtual ~BRISK();
|
|
|
|
|
|
|
|
// returns the descriptor size in bytes
|
|
|
|
int descriptorSize() const;
|
|
|
|
// returns the descriptor type
|
|
|
|
int descriptorType() const;
|
|
|
|
|
|
|
|
// Compute the BRISK features on an image
|
2013-02-25 00:14:01 +08:00
|
|
|
void operator()(InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints) const;
|
2012-08-23 20:52:01 +08:00
|
|
|
|
|
|
|
// Compute the BRISK features and descriptors on an image
|
2013-02-25 00:14:01 +08:00
|
|
|
void operator()( InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints,
|
2012-08-23 20:52:01 +08:00
|
|
|
OutputArray descriptors, bool useProvidedKeypoints=false ) const;
|
|
|
|
|
|
|
|
AlgorithmInfo* info() const;
|
|
|
|
|
|
|
|
// custom setup
|
|
|
|
CV_WRAP explicit BRISK(std::vector<float> &radiusList, std::vector<int> &numberList,
|
|
|
|
float dMax=5.85f, float dMin=8.2f, std::vector<int> indexChange=std::vector<int>());
|
|
|
|
|
|
|
|
// call this to generate the kernel:
|
|
|
|
// circle of radius r (pixels), with n points;
|
|
|
|
// short pairings with dMax, long pairings with dMin
|
|
|
|
CV_WRAP void generateKernel(std::vector<float> &radiusList,
|
|
|
|
std::vector<int> &numberList, float dMax=5.85f, float dMin=8.2f,
|
|
|
|
std::vector<int> indexChange=std::vector<int>());
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
|
|
|
void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2012-08-23 20:52:01 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
void computeKeypointsNoOrientation(InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints) const;
|
|
|
|
void computeDescriptorsAndOrOrientation(InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints,
|
2012-08-24 22:23:07 +08:00
|
|
|
OutputArray descriptors, bool doDescriptors, bool doOrientation,
|
|
|
|
bool useProvidedKeypoints) const;
|
|
|
|
|
2012-08-23 20:52:01 +08:00
|
|
|
// Feature parameters
|
|
|
|
CV_PROP_RW int threshold;
|
|
|
|
CV_PROP_RW int octaves;
|
|
|
|
|
|
|
|
// some helper structures for the Brisk pattern representation
|
|
|
|
struct BriskPatternPoint{
|
|
|
|
float x; // x coordinate relative to center
|
|
|
|
float y; // x coordinate relative to center
|
|
|
|
float sigma; // Gaussian smoothing sigma
|
|
|
|
};
|
|
|
|
struct BriskShortPair{
|
|
|
|
unsigned int i; // index of the first pattern point
|
|
|
|
unsigned int j; // index of other pattern point
|
|
|
|
};
|
|
|
|
struct BriskLongPair{
|
|
|
|
unsigned int i; // index of the first pattern point
|
|
|
|
unsigned int j; // index of other pattern point
|
|
|
|
int weighted_dx; // 1024.0/dx
|
|
|
|
int weighted_dy; // 1024.0/dy
|
|
|
|
};
|
|
|
|
inline int smoothedIntensity(const cv::Mat& image,
|
|
|
|
const cv::Mat& integral,const float key_x,
|
|
|
|
const float key_y, const unsigned int scale,
|
|
|
|
const unsigned int rot, const unsigned int point) const;
|
|
|
|
// pattern properties
|
|
|
|
BriskPatternPoint* patternPoints_; //[i][rotation][scale]
|
|
|
|
unsigned int points_; // total number of collocation points
|
|
|
|
float* scaleList_; // lists the scaling per scale index [scale]
|
|
|
|
unsigned int* sizeList_; // lists the total pattern size per scale index [scale]
|
|
|
|
static const unsigned int scales_; // scales discretization
|
|
|
|
static const float scalerange_; // span of sizes 40->4 Octaves - else, this needs to be adjusted...
|
|
|
|
static const unsigned int n_rot_; // discretization of the rotation look-up
|
|
|
|
|
|
|
|
// pairs
|
|
|
|
int strings_; // number of uchars the descriptor consists of
|
|
|
|
float dMax_; // short pair maximum distance
|
|
|
|
float dMin_; // long pair maximum distance
|
|
|
|
BriskShortPair* shortPairs_; // d<_dMax
|
|
|
|
BriskLongPair* longPairs_; // d>_dMin
|
|
|
|
unsigned int noShortPairs_; // number of shortParis
|
|
|
|
unsigned int noLongPairs_; // number of longParis
|
|
|
|
|
|
|
|
// general
|
|
|
|
static const float basicSize_;
|
|
|
|
};
|
|
|
|
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*!
|
|
|
|
ORB implementation.
|
|
|
|
*/
|
2012-07-06 23:41:57 +08:00
|
|
|
class CV_EXPORTS_W ORB : public Feature2D
|
2012-03-15 22:36:01 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// the size of the signature in bytes
|
|
|
|
enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2012-07-06 23:41:57 +08:00
|
|
|
CV_WRAP explicit ORB(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 );
|
2012-03-15 22:36:01 +08:00
|
|
|
|
|
|
|
// returns the descriptor size in bytes
|
|
|
|
int descriptorSize() const;
|
|
|
|
// returns the descriptor type
|
|
|
|
int descriptorType() const;
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
// Compute the ORB features and descriptors on an image
|
2013-02-25 00:14:01 +08:00
|
|
|
void operator()(InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints) const;
|
2012-03-15 22:36:01 +08:00
|
|
|
|
|
|
|
// Compute the ORB features and descriptors on an image
|
2013-02-25 00:14:01 +08:00
|
|
|
void operator()( InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints,
|
2012-03-15 22:36:01 +08:00
|
|
|
OutputArray descriptors, bool useProvidedKeypoints=false ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2011-05-11 20:59:36 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
|
|
|
void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
CV_PROP_RW int nfeatures;
|
|
|
|
CV_PROP_RW double scaleFactor;
|
|
|
|
CV_PROP_RW int nlevels;
|
|
|
|
CV_PROP_RW int edgeThreshold;
|
|
|
|
CV_PROP_RW int firstLevel;
|
|
|
|
CV_PROP_RW int WTA_K;
|
|
|
|
CV_PROP_RW int scoreType;
|
|
|
|
CV_PROP_RW int patchSize;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
typedef ORB OrbFeatureDetector;
|
|
|
|
typedef ORB OrbDescriptorExtractor;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-06-24 09:37:55 +08:00
|
|
|
/*!
|
|
|
|
FREAK implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS FREAK : public DescriptorExtractor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
* @param orientationNormalized enable orientation normalization
|
|
|
|
* @param scaleNormalized enable scale normalization
|
|
|
|
* @param patternScale scaling of the description pattern
|
|
|
|
* @param nbOctave number of octaves covered by the detected keypoints
|
|
|
|
* @param selectedPairs (optional) user defined selected pairs
|
|
|
|
*/
|
|
|
|
explicit FREAK( bool orientationNormalized = true,
|
|
|
|
bool scaleNormalized = true,
|
|
|
|
float patternScale = 22.0f,
|
|
|
|
int nOctaves = 4,
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<int>& selectedPairs = std::vector<int>());
|
2012-06-25 19:24:06 +08:00
|
|
|
FREAK( const FREAK& rhs );
|
2012-06-24 09:37:55 +08:00
|
|
|
FREAK& operator=( const FREAK& );
|
|
|
|
|
|
|
|
virtual ~FREAK();
|
|
|
|
|
|
|
|
/** returns the descriptor length in bytes */
|
|
|
|
virtual int descriptorSize() const;
|
|
|
|
|
|
|
|
/** returns the descriptor type */
|
|
|
|
virtual int descriptorType() const;
|
|
|
|
|
|
|
|
/** select the 512 "best description pairs"
|
|
|
|
* @param images grayscale images set
|
|
|
|
* @param keypoints set of detected keypoints
|
|
|
|
* @param corrThresh correlation threshold
|
|
|
|
* @param verbose print construction information
|
|
|
|
* @return list of best pair indexes
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<int> selectPairs( const std::vector<Mat>& images, std::vector<std::vector<KeyPoint> >& keypoints,
|
2012-06-24 09:37:55 +08:00
|
|
|
const double corrThresh = 0.7, bool verbose = true );
|
|
|
|
|
2012-06-25 19:24:06 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2012-06-24 09:37:55 +08:00
|
|
|
|
2012-06-25 19:24:06 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NB_SCALES = 64, NB_PAIRS = 512, NB_ORIENPAIRS = 45
|
|
|
|
};
|
2012-06-24 09:37:55 +08:00
|
|
|
|
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
2012-06-25 19:24:06 +08:00
|
|
|
void buildPattern();
|
|
|
|
uchar meanIntensity( const Mat& image, const Mat& integral, const float kp_x, const float kp_y,
|
2012-06-24 09:37:55 +08:00
|
|
|
const unsigned int scale, const unsigned int rot, const unsigned int point ) const;
|
|
|
|
|
2012-06-25 19:24:06 +08:00
|
|
|
bool orientationNormalized; //true if the orientation is normalized, false otherwise
|
2012-06-24 09:37:55 +08:00
|
|
|
bool scaleNormalized; //true if the scale is normalized, false otherwise
|
|
|
|
double patternScale; //scaling of the pattern
|
|
|
|
int nOctaves; //number of octaves
|
|
|
|
bool extAll; // true if all pairs need to be extracted for pairs selection
|
2012-06-25 19:24:06 +08:00
|
|
|
|
2012-06-24 09:37:55 +08:00
|
|
|
double patternScale0;
|
|
|
|
int nOctaves0;
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<int> selectedPairs0;
|
2012-06-24 09:37:55 +08:00
|
|
|
|
2012-06-25 19:24:06 +08:00
|
|
|
struct PatternPoint
|
|
|
|
{
|
|
|
|
float x; // x coordinate relative to center
|
|
|
|
float y; // x coordinate relative to center
|
|
|
|
float sigma; // Gaussian smoothing sigma
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DescriptionPair
|
|
|
|
{
|
|
|
|
uchar i; // index of the first point
|
|
|
|
uchar j; // index of the second point
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OrientationPair
|
|
|
|
{
|
|
|
|
uchar i; // index of the first point
|
|
|
|
uchar j; // index of the second point
|
|
|
|
int weight_dx; // dx/(norm_sq))*4096
|
|
|
|
int weight_dy; // dy/(norm_sq))*4096
|
|
|
|
};
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<PatternPoint> patternLookup; // look-up table for the pattern points (position+sigma of all points at all scales and orientation)
|
2012-06-24 09:37:55 +08:00
|
|
|
int patternSizes[NB_SCALES]; // size of the pattern at a specific scale (used to check if a point is within image boundaries)
|
|
|
|
DescriptionPair descriptionPairs[NB_PAIRS];
|
|
|
|
OrientationPair orientationPairs[NB_ORIENPAIRS];
|
|
|
|
};
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Maximal Stable Extremal Regions class.
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
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.
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
It returns the regions, each of those is encoded as a contour.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W MSER : public FeatureDetector
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
//! the full constructor
|
2012-05-22 23:53:39 +08:00
|
|
|
CV_WRAP explicit MSER( int _delta=5, int _min_area=60, int _max_area=14400,
|
2012-03-15 22:36:01 +08:00
|
|
|
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 );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
//! the operator that extracts the MSERs from the image or the specific part of it
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP_AS(detect) void operator()( const Mat& image, CV_OUT std::vector<std::vector<Point> >& msers,
|
2012-05-29 18:36:19 +08:00
|
|
|
const Mat& mask=Mat() ) const;
|
2012-03-15 22:36:01 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int delta;
|
|
|
|
int minArea;
|
|
|
|
int maxArea;
|
|
|
|
double maxVariation;
|
|
|
|
double minDiversity;
|
|
|
|
int maxEvolution;
|
|
|
|
double areaThreshold;
|
|
|
|
double minMargin;
|
|
|
|
int edgeBlurSize;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
typedef MSER MserFeatureDetector;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
/*!
|
|
|
|
The "Star" Detector.
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
The class implements the keypoint detector introduced by K. Konolige.
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W StarDetector : public FeatureDetector
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
//! the full constructor
|
|
|
|
CV_WRAP StarDetector(int _maxSize=45, int _responseThreshold=30,
|
|
|
|
int _lineThresholdProjected=10,
|
|
|
|
int _lineThresholdBinarized=8,
|
|
|
|
int _suppressNonmaxSize=5);
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
//! finds the keypoints in the image
|
|
|
|
CV_WRAP_AS(detect) void operator()(const Mat& image,
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_OUT std::vector<KeyPoint>& keypoints) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int maxSize;
|
|
|
|
int responseThreshold;
|
|
|
|
int lineThresholdProjected;
|
|
|
|
int lineThresholdBinarized;
|
|
|
|
int suppressNonmaxSize;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
//! detects corners using FAST algorithm by E. Rosten
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
|
2012-08-28 22:15:14 +08:00
|
|
|
int threshold, bool nonmaxSupression=true );
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
|
2012-08-28 22:15:14 +08:00
|
|
|
int threshold, bool nonmaxSupression, int type );
|
2012-03-15 22:36:01 +08:00
|
|
|
|
|
|
|
class CV_EXPORTS_W FastFeatureDetector : public FeatureDetector
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-07-31 21:17:58 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
CV_WRAP FastFeatureDetector( int threshold=10, bool nonmaxSuppression=true);
|
|
|
|
CV_WRAP FastFeatureDetector( int threshold, bool nonmaxSuppression, int type);
|
2012-03-15 22:36:01 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int threshold;
|
|
|
|
bool nonmaxSuppression;
|
2012-10-16 23:35:28 +08:00
|
|
|
int type;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
|
|
|
|
class CV_EXPORTS GFTTDetector : public FeatureDetector
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
GFTTDetector( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
|
|
|
|
int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
|
|
|
|
AlgorithmInfo* info() const;
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int nfeatures;
|
|
|
|
double qualityLevel;
|
|
|
|
double minDistance;
|
|
|
|
int blockSize;
|
|
|
|
bool useHarrisDetector;
|
|
|
|
double k;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
typedef GFTTDetector GoodFeaturesToTrackDetector;
|
|
|
|
typedef StarDetector StarFeatureDetector;
|
2011-05-21 06:25:53 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
class CV_EXPORTS_W SimpleBlobDetector : public FeatureDetector
|
2010-12-27 17:15:08 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-12 19:39:48 +08:00
|
|
|
struct CV_EXPORTS_W_SIMPLE Params
|
2010-12-27 17:15:08 +08:00
|
|
|
{
|
2012-03-12 19:39:48 +08:00
|
|
|
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;
|
2011-06-09 19:07:08 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_PROP_RW bool filterByColor;
|
|
|
|
CV_PROP_RW uchar blobColor;
|
2011-06-09 19:07:08 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_PROP_RW bool filterByArea;
|
|
|
|
CV_PROP_RW float minArea, maxArea;
|
2011-06-09 19:07:08 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_PROP_RW bool filterByCircularity;
|
|
|
|
CV_PROP_RW float minCircularity, maxCircularity;
|
2011-06-09 19:07:08 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_PROP_RW bool filterByInertia;
|
|
|
|
CV_PROP_RW float minInertiaRatio, maxInertiaRatio;
|
2011-06-09 19:07:08 +08:00
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_PROP_RW bool filterByConvexity;
|
|
|
|
CV_PROP_RW float minConvexity, maxConvexity;
|
2011-08-10 17:17:37 +08:00
|
|
|
|
|
|
|
void read( const FileNode& fn );
|
|
|
|
void write( FileStorage& fs ) const;
|
2010-12-27 17:15:08 +08:00
|
|
|
};
|
|
|
|
|
2012-03-12 19:39:48 +08:00
|
|
|
CV_WRAP SimpleBlobDetector(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
|
2011-01-31 22:18:50 +08:00
|
|
|
|
2011-08-10 17:17:37 +08:00
|
|
|
virtual void read( const FileNode& fn );
|
|
|
|
virtual void write( FileStorage& fs ) const;
|
|
|
|
|
2010-12-27 17:15:08 +08:00
|
|
|
protected:
|
|
|
|
struct CV_EXPORTS Center
|
|
|
|
{
|
2011-01-31 22:18:50 +08:00
|
|
|
Point2d location;
|
|
|
|
double radius;
|
|
|
|
double confidence;
|
2010-12-27 17:15:08 +08:00
|
|
|
};
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
|
|
|
virtual void findBlobs(const Mat &image, const Mat &binaryImage, std::vector<Center> ¢ers) const;
|
2010-12-27 17:15:08 +08:00
|
|
|
|
|
|
|
Params params;
|
2013-02-05 00:25:18 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2010-12-27 17:15:08 +08:00
|
|
|
};
|
|
|
|
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-09-30 22:21:22 +08:00
|
|
|
class CV_EXPORTS DenseFeatureDetector : public FeatureDetector
|
2010-09-25 00:55:12 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
explicit DenseFeatureDetector( float initFeatureScale=1.f, int featureScaleLevels=1,
|
|
|
|
float featureScaleMul=0.1f,
|
|
|
|
int initXyStep=6, int initImgBound=0,
|
|
|
|
bool varyXyStepWithScale=true,
|
|
|
|
bool varyImgBoundWithScale=false );
|
|
|
|
AlgorithmInfo* info() const;
|
2010-09-25 00:55:12 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-09-25 00:55:12 +08:00
|
|
|
|
2012-03-17 17:50:47 +08:00
|
|
|
double initFeatureScale;
|
2012-03-15 22:36:01 +08:00
|
|
|
int featureScaleLevels;
|
2012-03-17 17:50:47 +08:00
|
|
|
double featureScaleMul;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int initXyStep;
|
|
|
|
int initImgBound;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
bool varyXyStepWithScale;
|
|
|
|
bool varyImgBoundWithScale;
|
2010-09-25 00:55:12 +08:00
|
|
|
};
|
|
|
|
|
2010-08-04 00:28:52 +08:00
|
|
|
/*
|
|
|
|
* Adapts a detector to partition the source image into a grid and detect
|
|
|
|
* points in each cell.
|
|
|
|
*/
|
2011-09-15 16:07:37 +08:00
|
|
|
class CV_EXPORTS_W GridAdaptedFeatureDetector : public FeatureDetector
|
2010-08-04 00:28:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-03 18:00:24 +08:00
|
|
|
/*
|
|
|
|
* detector Detector that will be adapted.
|
|
|
|
* maxTotalKeypoints Maximum count of keypoints detected on the image. Only the strongest keypoints
|
|
|
|
* will be keeped.
|
|
|
|
* gridRows Grid rows count.
|
|
|
|
* gridCols Grid column count.
|
|
|
|
*/
|
2012-06-01 17:10:53 +08:00
|
|
|
CV_WRAP GridAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector=0,
|
2012-03-15 22:36:01 +08:00
|
|
|
int maxTotalKeypoints=1000,
|
|
|
|
int gridRows=4, int gridCols=4 );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// TODO implement read/write
|
2011-01-31 22:18:50 +08:00
|
|
|
virtual bool empty() const;
|
2012-06-25 19:24:06 +08:00
|
|
|
|
2012-06-01 17:10:53 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2010-08-04 00:28:52 +08:00
|
|
|
|
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
2010-08-04 00:28:52 +08:00
|
|
|
Ptr<FeatureDetector> detector;
|
|
|
|
int maxTotalKeypoints;
|
|
|
|
int gridRows;
|
|
|
|
int gridCols;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adapts a detector to detect points over multiple levels of a Gaussian
|
|
|
|
* pyramid. Useful for detectors that are not inherently scaled.
|
|
|
|
*/
|
2011-09-07 17:38:22 +08:00
|
|
|
class CV_EXPORTS_W PyramidAdaptedFeatureDetector : public FeatureDetector
|
2010-08-04 00:28:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-05-15 17:19:05 +08:00
|
|
|
// maxLevel - The 0-based index of the last pyramid layer
|
2011-09-07 17:38:22 +08:00
|
|
|
CV_WRAP PyramidAdaptedFeatureDetector( const Ptr<FeatureDetector>& detector, int maxLevel=2 );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// TODO implement read/write
|
2011-01-31 22:18:50 +08:00
|
|
|
virtual bool empty() const;
|
2010-08-04 00:28:52 +08:00
|
|
|
|
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
2010-08-04 00:28:52 +08:00
|
|
|
Ptr<FeatureDetector> detector;
|
2011-05-15 17:19:05 +08:00
|
|
|
int maxLevel;
|
2010-08-04 00:28:52 +08:00
|
|
|
};
|
|
|
|
|
2010-11-25 23:59:37 +08:00
|
|
|
/** \brief A feature detector parameter adjuster, this is used by the DynamicAdaptedFeatureDetector
|
2010-11-24 06:26:36 +08:00
|
|
|
* and is a wrapper for FeatureDetector that allow them to be adjusted after a detection
|
|
|
|
*/
|
2010-11-25 23:59:37 +08:00
|
|
|
class CV_EXPORTS AdjusterAdapter: public FeatureDetector
|
|
|
|
{
|
2012-05-29 18:36:19 +08:00
|
|
|
public:
|
2012-06-25 19:24:06 +08:00
|
|
|
/** pure virtual interface
|
|
|
|
*/
|
2010-11-25 23:59:37 +08:00
|
|
|
virtual ~AdjusterAdapter() {}
|
2011-05-11 19:53:53 +08:00
|
|
|
/** too few features were detected so, adjust the detector params accordingly
|
|
|
|
* \param min the minimum number of desired features
|
|
|
|
* \param n_detected the number previously detected
|
|
|
|
*/
|
|
|
|
virtual void tooFew(int min, int n_detected) = 0;
|
|
|
|
/** too many features were detected so, adjust the detector params accordingly
|
|
|
|
* \param max the maximum number of desired features
|
|
|
|
* \param n_detected the number previously detected
|
|
|
|
*/
|
|
|
|
virtual void tooMany(int max, int n_detected) = 0;
|
|
|
|
/** are params maxed out or still valid?
|
|
|
|
* \return false if the parameters can't be adjusted any more
|
|
|
|
*/
|
|
|
|
virtual bool good() const = 0;
|
|
|
|
|
|
|
|
virtual Ptr<AdjusterAdapter> clone() const = 0;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
static Ptr<AdjusterAdapter> create( const String& detectorType );
|
2010-11-24 06:26:36 +08:00
|
|
|
};
|
2010-11-23 07:59:25 +08:00
|
|
|
/** \brief an adaptively adjusting detector that iteratively detects until the desired number
|
|
|
|
* of features are detected.
|
|
|
|
* Beware that this is not thread safe - as the adjustment of parameters breaks the const
|
|
|
|
* of the detection routine...
|
|
|
|
* /TODO Make this const correct and thread safe
|
2010-11-24 06:45:49 +08:00
|
|
|
*
|
|
|
|
* sample usage:
|
|
|
|
//will create a detector that attempts to find 100 - 110 FAST Keypoints, and will at most run
|
|
|
|
//FAST feature detection 10 times until that number of keypoints are found
|
2010-11-25 23:59:37 +08:00
|
|
|
Ptr<FeatureDetector> detector(new DynamicAdaptedFeatureDetector(new FastAdjuster(20,true),100, 110, 10));
|
2010-11-24 06:45:49 +08:00
|
|
|
|
2010-11-23 07:59:25 +08:00
|
|
|
*/
|
2010-11-25 23:59:37 +08:00
|
|
|
class CV_EXPORTS DynamicAdaptedFeatureDetector: public FeatureDetector
|
|
|
|
{
|
2010-11-23 07:59:25 +08:00
|
|
|
public:
|
|
|
|
|
2012-05-29 18:36:19 +08:00
|
|
|
/** \param adjuster an AdjusterAdapter that will do the detection and parameter adjustment
|
2011-05-11 19:53:53 +08:00
|
|
|
* \param max_features the maximum desired number of features
|
|
|
|
* \param max_iters the maximum number of times to try to adjust the feature detector params
|
2012-06-25 19:24:06 +08:00
|
|
|
* for the FastAdjuster this can be high, but with Star or Surf this can get time consuming
|
2011-05-11 19:53:53 +08:00
|
|
|
* \param min_features the minimum desired features
|
|
|
|
*/
|
2012-05-29 18:36:19 +08:00
|
|
|
DynamicAdaptedFeatureDetector( const Ptr<AdjusterAdapter>& adjuster, int min_features=400, int max_features=500, int max_iters=5 );
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2011-01-31 22:18:50 +08:00
|
|
|
virtual bool empty() const;
|
|
|
|
|
2010-11-23 07:59:25 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2010-11-23 07:59:25 +08:00
|
|
|
private:
|
2012-06-25 19:24:06 +08:00
|
|
|
DynamicAdaptedFeatureDetector& operator=(const DynamicAdaptedFeatureDetector&);
|
|
|
|
DynamicAdaptedFeatureDetector(const DynamicAdaptedFeatureDetector&);
|
2011-05-11 21:37:20 +08:00
|
|
|
|
2011-05-11 19:53:53 +08:00
|
|
|
int escape_iters_;
|
|
|
|
int min_features_, max_features_;
|
|
|
|
const Ptr<AdjusterAdapter> adjuster_;
|
2010-11-23 07:59:25 +08:00
|
|
|
};
|
|
|
|
|
2010-11-24 06:45:49 +08:00
|
|
|
/**\brief an adjust for the FAST detector. This will basically decrement or increment the
|
2011-05-11 19:53:53 +08:00
|
|
|
* threshold by 1
|
2010-11-24 06:45:49 +08:00
|
|
|
*/
|
2010-11-25 23:59:37 +08:00
|
|
|
class CV_EXPORTS FastAdjuster: public AdjusterAdapter
|
|
|
|
{
|
2010-11-24 06:26:36 +08:00
|
|
|
public:
|
2011-05-11 19:53:53 +08:00
|
|
|
/**\param init_thresh the initial threshold to start with, default = 20
|
|
|
|
* \param nonmax whether to use non max or not for fast feature detection
|
|
|
|
*/
|
2011-05-11 20:13:58 +08:00
|
|
|
FastAdjuster(int init_thresh=20, bool nonmax=true, int min_thresh=1, int max_thresh=200);
|
2011-05-11 19:53:53 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
virtual void tooFew(int minv, int n_detected);
|
|
|
|
virtual void tooMany(int maxv, int n_detected);
|
2011-05-11 19:53:53 +08:00
|
|
|
virtual bool good() const;
|
|
|
|
|
|
|
|
virtual Ptr<AdjusterAdapter> clone() const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2010-11-24 06:26:36 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2011-05-11 19:53:53 +08:00
|
|
|
int thresh_;
|
|
|
|
bool nonmax_;
|
2011-05-11 20:13:58 +08:00
|
|
|
int init_thresh_, min_thresh_, max_thresh_;
|
2010-11-24 06:26:36 +08:00
|
|
|
};
|
2010-11-23 07:59:25 +08:00
|
|
|
|
2010-11-24 06:45:49 +08:00
|
|
|
|
|
|
|
/** An adjuster for StarFeatureDetector, this one adjusts the responseThreshold for now
|
|
|
|
* TODO find a faster way to converge the parameters for Star - use CvStarDetectorParams
|
|
|
|
*/
|
2010-11-25 23:59:37 +08:00
|
|
|
class CV_EXPORTS StarAdjuster: public AdjusterAdapter
|
|
|
|
{
|
|
|
|
public:
|
2011-05-11 20:13:58 +08:00
|
|
|
StarAdjuster(double initial_thresh=30.0, double min_thresh=2., double max_thresh=200.);
|
2011-05-11 19:53:53 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
virtual void tooFew(int minv, int n_detected);
|
|
|
|
virtual void tooMany(int maxv, int n_detected);
|
2011-05-11 19:53:53 +08:00
|
|
|
virtual bool good() const;
|
|
|
|
|
|
|
|
virtual Ptr<AdjusterAdapter> clone() const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2010-11-24 06:26:36 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2011-05-11 20:13:58 +08:00
|
|
|
double thresh_, init_thresh_, min_thresh_, max_thresh_;
|
2010-11-23 07:59:25 +08:00
|
|
|
};
|
|
|
|
|
2010-11-25 23:59:37 +08:00
|
|
|
class CV_EXPORTS SurfAdjuster: public AdjusterAdapter
|
|
|
|
{
|
|
|
|
public:
|
2011-05-11 20:13:58 +08:00
|
|
|
SurfAdjuster( double initial_thresh=400.f, double min_thresh=2, double max_thresh=1000 );
|
2011-05-11 19:53:53 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
virtual void tooFew(int minv, int n_detected);
|
|
|
|
virtual void tooMany(int maxv, int n_detected);
|
2011-05-11 19:53:53 +08:00
|
|
|
virtual bool good() const;
|
|
|
|
|
|
|
|
virtual Ptr<AdjusterAdapter> clone() const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2010-11-24 06:26:36 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2011-05-11 20:13:58 +08:00
|
|
|
double thresh_, init_thresh_, min_thresh_, max_thresh_;
|
2010-11-23 07:59:25 +08:00
|
|
|
};
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS Mat windowedMatchingMask( const std::vector<KeyPoint>& keypoints1, const std::vector<KeyPoint>& keypoints2,
|
2010-08-05 20:19:26 +08:00
|
|
|
float maxDeltaX, float maxDeltaY );
|
|
|
|
|
2010-07-26 16:58:46 +08:00
|
|
|
|
2011-01-31 22:18:50 +08:00
|
|
|
|
2010-09-23 18:53:36 +08:00
|
|
|
/*
|
2010-11-15 18:24:38 +08:00
|
|
|
* OpponentColorDescriptorExtractor
|
|
|
|
*
|
2010-09-23 18:53:36 +08:00
|
|
|
* Adapts a descriptor extractor to compute descripors in Opponent Color Space
|
|
|
|
* (refer to van de Sande et al., CGIV 2008 "Color Descriptors for Object Category Recognition").
|
|
|
|
* Input RGB image is transformed in Opponent Color Space. Then unadapted descriptor extractor
|
|
|
|
* (set in constructor) computes descriptors on each of the three channel and concatenate
|
|
|
|
* them into a single color descriptor.
|
|
|
|
*/
|
2010-11-12 16:20:51 +08:00
|
|
|
class CV_EXPORTS OpponentColorDescriptorExtractor : public DescriptorExtractor
|
2010-09-23 18:53:36 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
OpponentColorDescriptorExtractor( const Ptr<DescriptorExtractor>& descriptorExtractor );
|
2010-09-23 18:53:36 +08:00
|
|
|
|
|
|
|
virtual void read( const FileNode& );
|
|
|
|
virtual void write( FileStorage& ) const;
|
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual int descriptorSize() const;
|
|
|
|
virtual int descriptorType() const;
|
2010-09-23 18:53:36 +08:00
|
|
|
|
2011-01-31 22:18:50 +08:00
|
|
|
virtual bool empty() const;
|
|
|
|
|
2010-09-23 18:53:36 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
|
|
|
Ptr<DescriptorExtractor> descriptorExtractor;
|
2010-09-23 18:53:36 +08:00
|
|
|
};
|
|
|
|
|
2010-11-15 18:24:38 +08:00
|
|
|
/*
|
|
|
|
* BRIEF Descriptor
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS BriefDescriptorExtractor : public DescriptorExtractor
|
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
static const int PATCH_SIZE = 48;
|
|
|
|
static const int KERNEL_SIZE = 9;
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2010-11-24 01:00:55 +08:00
|
|
|
// bytes is a length of descriptor in bytes. It can be equal 16, 32 or 64 bytes.
|
|
|
|
BriefDescriptorExtractor( int bytes = 32 );
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2011-08-04 17:56:10 +08:00
|
|
|
virtual void read( const FileNode& );
|
|
|
|
virtual void write( FileStorage& ) const;
|
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual int descriptorSize() const;
|
|
|
|
virtual int descriptorType() const;
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
/// @todo read and write for brief
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2012-03-29 11:06:59 +08:00
|
|
|
AlgorithmInfo* info() const;
|
|
|
|
|
2010-11-15 18:24:38 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void computeImpl(const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors) const;
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
typedef void(*PixelTestFn)(const Mat&, const std::vector<KeyPoint>&, Mat&);
|
2010-11-15 18:24:38 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
int bytes_;
|
|
|
|
PixelTestFn test_fn_;
|
2010-11-15 18:24:38 +08:00
|
|
|
};
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
/****************************************************************************************\
|
2012-04-30 22:33:52 +08:00
|
|
|
* Distance *
|
2010-05-12 01:44:00 +08:00
|
|
|
\****************************************************************************************/
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
template<typename T>
|
|
|
|
struct CV_EXPORTS Accumulator
|
|
|
|
{
|
|
|
|
typedef T Type;
|
|
|
|
};
|
|
|
|
|
2010-11-25 18:05:03 +08:00
|
|
|
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; };
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2011-08-08 21:18:12 +08:00
|
|
|
/*
|
2011-08-08 22:03:37 +08:00
|
|
|
* Squared Euclidean distance functor
|
2011-08-08 21:18:12 +08:00
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS SL2
|
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
enum { normType = NORM_L2SQR };
|
2011-08-08 21:18:12 +08:00
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2011-08-08 21:18:12 +08:00
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
2011-10-11 23:13:53 +08:00
|
|
|
return normL2Sqr<ValueType, ResultType>(a, b, size);
|
2011-08-08 21:18:12 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
/*
|
2011-08-05 22:05:41 +08:00
|
|
|
* Euclidean distance functor
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS L2
|
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
enum { normType = NORM_L2 };
|
2010-05-12 01:44:00 +08:00
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
2013-02-25 00:14:01 +08:00
|
|
|
return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-28 21:06:24 +08:00
|
|
|
/*
|
|
|
|
* Manhattan distance (city block distance) functor
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
struct CV_EXPORTS L1
|
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
enum { normType = NORM_L1 };
|
2010-06-28 21:06:24 +08:00
|
|
|
typedef T ValueType;
|
|
|
|
typedef typename Accumulator<T>::Type ResultType;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-06-28 21:06:24 +08:00
|
|
|
ResultType operator()( const T* a, const T* b, int size ) const
|
|
|
|
{
|
2011-10-11 23:13:53 +08:00
|
|
|
return normL1<ValueType, ResultType>(a, b, size);
|
2010-06-28 21:06:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
/*
|
2010-11-23 07:59:25 +08:00
|
|
|
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
2010-11-24 06:26:36 +08:00
|
|
|
* bit count of A exclusive XOR'ed with B
|
2010-11-23 02:27:08 +08:00
|
|
|
*/
|
2011-10-11 23:13:53 +08:00
|
|
|
struct CV_EXPORTS Hamming
|
2010-11-23 02:27:08 +08:00
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
enum { normType = NORM_HAMMING };
|
2010-11-23 02:27:08 +08:00
|
|
|
typedef unsigned char ValueType;
|
|
|
|
typedef int ResultType;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-11-24 06:45:49 +08:00
|
|
|
/** this will count the bits in a ^ b
|
|
|
|
*/
|
2011-10-11 23:13:53 +08:00
|
|
|
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
|
|
|
{
|
|
|
|
return normHamming(a, b, size);
|
|
|
|
}
|
2010-11-23 02:27:08 +08:00
|
|
|
};
|
2010-11-24 06:26:36 +08:00
|
|
|
|
2011-10-11 23:13:53 +08:00
|
|
|
typedef Hamming HammingLUT;
|
2010-06-11 17:38:39 +08:00
|
|
|
|
2011-11-08 20:01:49 +08:00
|
|
|
template<int cellsize> struct CV_EXPORTS HammingMultilevel
|
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
enum { normType = NORM_HAMMING + (cellsize>1) };
|
2011-11-08 20:01:49 +08:00
|
|
|
typedef unsigned char ValueType;
|
|
|
|
typedef int ResultType;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2011-11-08 20:01:49 +08:00
|
|
|
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
|
|
|
{
|
|
|
|
return normHamming(a, b, size, cellsize);
|
|
|
|
}
|
2012-05-29 18:36:19 +08:00
|
|
|
};
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
/****************************************************************************************\
|
|
|
|
* DescriptorMatcher *
|
|
|
|
\****************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Abstract base class for matching two sets of descriptors.
|
|
|
|
*/
|
2012-03-15 22:36:01 +08:00
|
|
|
class CV_EXPORTS_W DescriptorMatcher : public Algorithm
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual ~DescriptorMatcher();
|
|
|
|
|
2012-06-25 19:24:06 +08:00
|
|
|
/*
|
2010-10-29 16:44:42 +08:00
|
|
|
* Add descriptors to train descriptor collection.
|
2010-11-23 02:27:08 +08:00
|
|
|
* descriptors Descriptors to add. Each descriptors[i] is a descriptors set from one image.
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP virtual void add( const std::vector<Mat>& descriptors );
|
2010-05-12 01:44:00 +08:00
|
|
|
/*
|
2010-11-23 02:27:08 +08:00
|
|
|
* Get train descriptors collection.
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP const std::vector<Mat>& getTrainDescriptors() const;
|
2010-05-12 01:44:00 +08:00
|
|
|
/*
|
2010-11-23 02:27:08 +08:00
|
|
|
* Clear train descriptors collection.
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2011-09-15 19:10:06 +08:00
|
|
|
CV_WRAP virtual void clear();
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
/*
|
|
|
|
* Return true if there are not train descriptors in collection.
|
|
|
|
*/
|
2011-09-15 19:10:06 +08:00
|
|
|
CV_WRAP virtual bool empty() const;
|
2010-11-23 02:27:08 +08:00
|
|
|
/*
|
|
|
|
* Return true if the matcher supports mask in match methods.
|
|
|
|
*/
|
2011-09-15 19:10:06 +08:00
|
|
|
CV_WRAP virtual bool isMaskSupported() const = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
/*
|
2010-11-23 02:27:08 +08:00
|
|
|
* 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
|
2011-05-22 04:17:45 +08:00
|
|
|
* of this method, other matchers really train their inner structures
|
2010-11-23 02:27:08 +08:00
|
|
|
* (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).
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2011-09-15 19:10:06 +08:00
|
|
|
CV_WRAP virtual void train();
|
2010-06-11 17:38:39 +08:00
|
|
|
/*
|
2010-10-29 16:44:42 +08:00
|
|
|
* Group of methods to match descriptors from image pair.
|
2010-11-23 02:27:08 +08:00
|
|
|
* Method train() is run in this methods.
|
2010-06-11 17:38:39 +08:00
|
|
|
*/
|
2010-10-29 16:44:42 +08:00
|
|
|
// Find one best match for each query descriptor (if mask is empty).
|
2011-09-07 17:38:22 +08:00
|
|
|
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_OUT std::vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
// 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.
|
2011-09-07 17:38:22 +08:00
|
|
|
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
2010-10-29 16:44:42 +08:00
|
|
|
const Mat& mask=Mat(), bool compactResult=false ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
// Find best matches for each query descriptor which have distance less than
|
|
|
|
// maxDistance (in increasing order of distances).
|
|
|
|
void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2010-10-29 16:44:42 +08:00
|
|
|
const Mat& mask=Mat(), bool compactResult=false ) const;
|
2010-06-11 17:38:39 +08:00
|
|
|
/*
|
2010-10-29 16:44:42 +08:00
|
|
|
* Group of methods to match descriptors from one image to image set.
|
|
|
|
* See description of similar methods for matching image pair above.
|
2010-06-11 17:38:39 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_WRAP void match( const Mat& queryDescriptors, CV_OUT std::vector<DMatch>& matches,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>() );
|
|
|
|
CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
|
|
|
void radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
// Reads matcher object from a file node
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual void read( const FileNode& );
|
2010-10-29 16:44:42 +08:00
|
|
|
// Writes matcher object to a file storage
|
2010-11-23 02:27:08 +08:00
|
|
|
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;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType );
|
2010-10-29 16:44:42 +08:00
|
|
|
protected:
|
2010-06-16 16:56:53 +08:00
|
|
|
/*
|
2010-10-29 16:44:42 +08:00
|
|
|
* Class to work with descriptors from several images as with one merged matrix.
|
2010-11-23 02:27:08 +08:00
|
|
|
* It is used e.g. in FlannBasedMatcher.
|
2010-06-16 16:56:53 +08:00
|
|
|
*/
|
2010-10-29 22:39:23 +08:00
|
|
|
class CV_EXPORTS DescriptorCollection
|
2010-10-29 16:44:42 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
DescriptorCollection();
|
|
|
|
DescriptorCollection( const DescriptorCollection& collection );
|
|
|
|
virtual ~DescriptorCollection();
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here.
|
2013-02-25 00:14:01 +08:00
|
|
|
void set( const std::vector<Mat>& descriptors );
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void clear();
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
const Mat& getDescriptors() const;
|
2010-10-29 16:44:42 +08:00
|
|
|
const Mat getDescriptor( int imgIdx, int localDescIdx ) const;
|
|
|
|
const Mat getDescriptor( int globalDescIdx ) const;
|
|
|
|
void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
int size() const;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
protected:
|
2010-11-23 02:27:08 +08:00
|
|
|
Mat mergedDescriptors;
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<int> startIdxs;
|
2010-10-29 16:44:42 +08:00
|
|
|
};
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// 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().
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void knnMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false ) = 0;
|
|
|
|
virtual void radiusMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false ) = 0;
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
static bool isPossibleMatch( const Mat& mask, int queryIdx, int trainIdx );
|
2013-02-25 00:14:01 +08:00
|
|
|
static bool isMaskedOut( const std::vector<Mat>& masks, int queryIdx );
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
static Mat clone_op( Mat m ) { return m.clone(); }
|
2013-02-25 00:14:01 +08:00
|
|
|
void checkMasks( const std::vector<Mat>& masks, int queryDescriptorsCount ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// Collection of descriptors from train images.
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<Mat> trainDescCollection;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2010-11-03 18:00:24 +08:00
|
|
|
* 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>.
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2012-07-12 01:13:43 +08:00
|
|
|
class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
|
2010-11-03 18:00:24 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-02-01 05:07:27 +08:00
|
|
|
CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false );
|
2012-03-15 22:36:01 +08:00
|
|
|
virtual ~BFMatcher() {}
|
2010-11-03 18:00:24 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual bool isMaskSupported() const { return true; }
|
|
|
|
|
|
|
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
2010-11-03 18:00:24 +08:00
|
|
|
|
2013-02-01 05:07:27 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2010-11-03 18:00:24 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void knnMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
|
|
|
virtual void radiusMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
2010-11-03 18:00:24 +08:00
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
int normType;
|
|
|
|
bool crossCheck;
|
2010-11-03 18:00:24 +08:00
|
|
|
};
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
/*
|
2010-10-29 16:44:42 +08:00
|
|
|
* Flann based matcher
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2011-09-15 19:10:06 +08:00
|
|
|
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-09-15 19:10:06 +08:00
|
|
|
CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=new flann::KDTreeIndexParams(),
|
2010-11-23 02:27:08 +08:00
|
|
|
const Ptr<flann::SearchParams>& searchParams=new flann::SearchParams() );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void add( const std::vector<Mat>& descriptors );
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void clear();
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2011-08-04 22:13:07 +08:00
|
|
|
// Reads matcher object from a file node
|
|
|
|
virtual void read( const FileNode& );
|
|
|
|
// Writes matcher object to a file storage
|
|
|
|
virtual void write( FileStorage& ) const;
|
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void train();
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual bool isMaskSupported() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
2010-05-26 19:27:56 +08:00
|
|
|
|
2013-02-01 05:07:27 +08:00
|
|
|
AlgorithmInfo* info() const;
|
2010-11-23 02:27:08 +08:00
|
|
|
protected:
|
|
|
|
static void convertToDMatches( const DescriptorCollection& descriptors,
|
|
|
|
const Mat& indices, const Mat& distances,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<std::vector<DMatch> >& matches );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void knnMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
|
|
|
virtual void radiusMatchImpl( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
2010-11-23 02:27:08 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
Ptr<flann::IndexParams> indexParams;
|
|
|
|
Ptr<flann::SearchParams> searchParams;
|
2011-02-02 23:47:08 +08:00
|
|
|
Ptr<flann::Index> flannIndex;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
|
|
|
DescriptorCollection mergedDescriptors;
|
|
|
|
int addedDescCount;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
/****************************************************************************************\
|
|
|
|
* GenericDescriptorMatcher *
|
|
|
|
\****************************************************************************************/
|
2010-05-12 01:44:00 +08:00
|
|
|
/*
|
2010-11-16 23:42:31 +08:00
|
|
|
* Abstract interface for a keypoint descriptor and matcher
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2010-10-29 16:44:42 +08:00
|
|
|
class GenericDescriptorMatcher;
|
|
|
|
typedef GenericDescriptorMatcher GenericDescriptorMatch;
|
|
|
|
|
|
|
|
class CV_EXPORTS GenericDescriptorMatcher
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
GenericDescriptorMatcher();
|
|
|
|
virtual ~GenericDescriptorMatcher();
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
2010-11-23 02:27:08 +08:00
|
|
|
* Add train collection: images and keypoints from them.
|
|
|
|
* images A set of train images.
|
|
|
|
* ketpoints Keypoint collection that have been detected on train images.
|
|
|
|
*
|
|
|
|
* Keypoints for which a descriptor cannot be computed are removed. Such keypoints
|
|
|
|
* must be filtered in this method befor adding keypoints to train collection "trainPointCollection".
|
|
|
|
* If inheritor class need perform such prefiltering the method add() must be overloaded.
|
|
|
|
* In the other class methods programmer has access to the train keypoints by a constant link.
|
2010-10-29 16:44:42 +08:00
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void add( const std::vector<Mat>& images,
|
|
|
|
std::vector<std::vector<KeyPoint> >& keypoints );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<Mat>& getTrainImages() const;
|
|
|
|
const std::vector<std::vector<KeyPoint> >& getTrainKeypoints() const;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
/*
|
|
|
|
* Clear images and keypoints storing in train collection.
|
|
|
|
*/
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void clear();
|
2010-11-23 02:27:08 +08:00
|
|
|
/*
|
|
|
|
* Returns true if matcher supports mask to match descriptors.
|
|
|
|
*/
|
|
|
|
virtual bool isMaskSupported() = 0;
|
|
|
|
/*
|
|
|
|
* Train some inner structures (e.g. flann index or decision trees).
|
|
|
|
* train() methods is run every time in matching methods. So the method implementation
|
|
|
|
* should has a check whether these inner structures need be trained/retrained or not.
|
|
|
|
*/
|
|
|
|
virtual void train();
|
2010-11-04 00:39:58 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
|
|
|
* Classifies query keypoints.
|
|
|
|
* queryImage The query image
|
2010-11-23 02:27:08 +08:00
|
|
|
* queryKeypoints Keypoints from the query image
|
2010-10-29 16:44:42 +08:00
|
|
|
* trainImage The train image
|
2010-11-23 02:27:08 +08:00
|
|
|
* trainKeypoints Keypoints from the train image
|
2010-10-29 16:44:42 +08:00
|
|
|
*/
|
|
|
|
// Classify keypoints from query image under one train image.
|
2013-02-25 00:14:01 +08:00
|
|
|
void classify( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
const Mat& trainImage, std::vector<KeyPoint>& trainKeypoints ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
// Classify keypoints from query image under train image collection.
|
2013-02-25 00:14:01 +08:00
|
|
|
void classify( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
|
|
|
* Group of methods to match keypoints from image pair.
|
2010-11-23 02:27:08 +08:00
|
|
|
* Keypoints for which a descriptor cannot be computed are removed.
|
|
|
|
* train() method is called here.
|
2010-10-29 16:44:42 +08:00
|
|
|
*/
|
|
|
|
// Find one best match for each query descriptor (if mask is empty).
|
2013-02-25 00:14:01 +08:00
|
|
|
void match( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
const Mat& trainImage, std::vector<KeyPoint>& trainKeypoints,
|
|
|
|
std::vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
2010-11-23 02:27:08 +08:00
|
|
|
// Find k best matches for each query keypoint (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.
|
2010-10-29 16:44:42 +08:00
|
|
|
// If compactResult is true matches vector will not contain matches for fully masked out query descriptors.
|
2013-02-25 00:14:01 +08:00
|
|
|
void knnMatch( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
const Mat& trainImage, std::vector<KeyPoint>& trainKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, int k,
|
2010-11-23 02:27:08 +08:00
|
|
|
const Mat& mask=Mat(), bool compactResult=false ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
// Find best matches for each query descriptor which have distance less than maxDistance (in increasing order of distances).
|
2013-02-25 00:14:01 +08:00
|
|
|
void radiusMatch( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
const Mat& trainImage, std::vector<KeyPoint>& trainKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2010-11-23 02:27:08 +08:00
|
|
|
const Mat& mask=Mat(), bool compactResult=false ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
|
|
|
* Group of methods to match keypoints from one image to image set.
|
|
|
|
* See description of similar methods for matching image pair above.
|
|
|
|
*/
|
2013-02-25 00:14:01 +08:00
|
|
|
void match( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<DMatch>& matches, const std::vector<Mat>& masks=std::vector<Mat>() );
|
|
|
|
void knnMatch( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
|
|
|
void radiusMatch( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false );
|
2010-10-29 16:44:42 +08:00
|
|
|
|
|
|
|
// Reads matcher object from a file node
|
2012-05-28 15:36:14 +08:00
|
|
|
virtual void read( const FileNode& fn );
|
2010-10-29 16:44:42 +08:00
|
|
|
// Writes matcher object to a file storage
|
2012-05-28 15:36:14 +08:00
|
|
|
virtual void write( FileStorage& fs ) const;
|
2010-06-11 17:38:39 +08:00
|
|
|
|
2011-01-31 22:18:50 +08:00
|
|
|
// Return true if matching object is empty (e.g. feature detector or descriptor matcher are empty)
|
|
|
|
virtual bool empty() const;
|
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
// 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<GenericDescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
static Ptr<GenericDescriptorMatcher> create( const String& genericDescritptorMatcherType,
|
|
|
|
const String ¶msFilename=String() );
|
2010-11-25 23:59:37 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
protected:
|
|
|
|
// 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().
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void knnMatchImpl( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks, bool compactResult ) = 0;
|
|
|
|
virtual void radiusMatchImpl( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks, bool compactResult ) = 0;
|
2010-10-29 16:44:42 +08:00
|
|
|
/*
|
|
|
|
* A storage for sets of keypoints together with corresponding images and class IDs
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS KeyPointCollection
|
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
KeyPointCollection();
|
|
|
|
KeyPointCollection( const KeyPointCollection& collection );
|
2013-02-25 00:14:01 +08:00
|
|
|
void add( const std::vector<Mat>& images, const std::vector<std::vector<KeyPoint> >& keypoints );
|
2010-10-29 16:44:42 +08:00
|
|
|
void clear();
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
// Returns the total number of keypoints in the collection
|
2010-11-23 02:27:08 +08:00
|
|
|
size_t keypointCount() const;
|
|
|
|
size_t imageCount() const;
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<std::vector<KeyPoint> >& getKeypoints() const;
|
|
|
|
const std::vector<KeyPoint>& getKeypoints( int imgIdx ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
const KeyPoint& getKeyPoint( int imgIdx, int localPointIdx ) const;
|
|
|
|
const KeyPoint& getKeyPoint( int globalPointIdx ) const;
|
|
|
|
void getLocalIdx( int globalPointIdx, int& imgIdx, int& localPointIdx ) const;
|
2010-06-10 15:59:18 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<Mat>& getImages() const;
|
2010-11-23 02:27:08 +08:00
|
|
|
const Mat& getImage( int imgIdx ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
|
|
|
protected:
|
2010-11-23 02:27:08 +08:00
|
|
|
int pointCount;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<Mat> images;
|
|
|
|
std::vector<std::vector<KeyPoint> > keypoints;
|
2010-11-23 02:27:08 +08:00
|
|
|
// global indices of the first points in each image, startIndices.size() = keypoints.size()
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<int> startIndices;
|
2010-11-23 02:27:08 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
static Mat clone_op( Mat m ) { return m.clone(); }
|
2010-10-29 16:44:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
KeyPointCollection trainPointCollection;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
2010-10-29 16:44:42 +08:00
|
|
|
* VectorDescriptorMatcher *
|
2010-05-12 01:44:00 +08:00
|
|
|
\****************************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2010-05-21 00:16:28 +08:00
|
|
|
* A class used for matching descriptors that can be described as vectors in a finite-dimensional space
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2010-10-29 16:44:42 +08:00
|
|
|
class VectorDescriptorMatcher;
|
|
|
|
typedef VectorDescriptorMatcher VectorDescriptorMatch;
|
|
|
|
|
|
|
|
class CV_EXPORTS VectorDescriptorMatcher : public GenericDescriptorMatcher
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
VectorDescriptorMatcher( const Ptr<DescriptorExtractor>& extractor, const Ptr<DescriptorMatcher>& matcher );
|
|
|
|
virtual ~VectorDescriptorMatcher();
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void add( const std::vector<Mat>& imgCollection,
|
|
|
|
std::vector<std::vector<KeyPoint> >& pointCollection );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void clear();
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2010-10-29 16:44:42 +08:00
|
|
|
virtual void train();
|
2010-05-26 23:00:03 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual bool isMaskSupported();
|
2010-11-04 00:39:58 +08:00
|
|
|
|
2010-07-26 16:58:46 +08:00
|
|
|
virtual void read( const FileNode& fn );
|
|
|
|
virtual void write( FileStorage& fs ) const;
|
2011-01-31 22:18:50 +08:00
|
|
|
virtual bool empty() const;
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual Ptr<GenericDescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2010-11-23 02:27:08 +08:00
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
virtual void knnMatchImpl( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, int k,
|
|
|
|
const std::vector<Mat>& masks, bool compactResult );
|
|
|
|
virtual void radiusMatchImpl( const Mat& queryImage, std::vector<KeyPoint>& queryKeypoints,
|
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
|
|
const std::vector<Mat>& masks, bool compactResult );
|
2010-10-29 16:44:42 +08:00
|
|
|
|
2010-07-12 19:56:11 +08:00
|
|
|
Ptr<DescriptorExtractor> extractor;
|
|
|
|
Ptr<DescriptorMatcher> matcher;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2010-08-05 20:19:26 +08:00
|
|
|
/****************************************************************************************\
|
|
|
|
* Drawing functions *
|
|
|
|
\****************************************************************************************/
|
2010-06-12 01:15:43 +08:00
|
|
|
struct CV_EXPORTS DrawMatchesFlags
|
|
|
|
{
|
|
|
|
enum{ DEFAULT = 0, // Output image matrix will be created (Mat::create),
|
2010-06-12 18:11:57 +08:00
|
|
|
// i.e. existing memory of output image may be reused.
|
2010-06-12 01:15:43 +08:00
|
|
|
// Two source image, matches and single keypoints will be drawn.
|
2010-08-04 00:28:52 +08:00
|
|
|
// For each keypoint only the center point will be drawn (without
|
|
|
|
// the circle around keypoint with keypoint size and orientation).
|
2010-06-12 01:15:43 +08:00
|
|
|
DRAW_OVER_OUTIMG = 1, // Output image matrix will not be created (Mat::create).
|
|
|
|
// Matches will be drawn on existing content of output image.
|
2010-08-04 00:28:52 +08:00
|
|
|
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
|
2010-08-05 20:19:26 +08:00
|
|
|
// orientation will be drawn.
|
2010-06-12 01:15:43 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2010-08-04 00:28:52 +08:00
|
|
|
// Draw keypoints.
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS_W void drawKeypoints( const Mat& image, const std::vector<KeyPoint>& keypoints, CV_OUT Mat& outImage,
|
2010-08-04 00:28:52 +08:00
|
|
|
const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT );
|
|
|
|
|
2010-06-12 01:15:43 +08:00
|
|
|
// Draws matches of keypints from two images on output image.
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void drawMatches( const Mat& img1, const std::vector<KeyPoint>& keypoints1,
|
|
|
|
const Mat& img2, const std::vector<KeyPoint>& keypoints2,
|
|
|
|
const std::vector<DMatch>& matches1to2, Mat& outImg,
|
2010-08-04 00:28:52 +08:00
|
|
|
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<char>& matchesMask=std::vector<char>(), int flags=DrawMatchesFlags::DEFAULT );
|
2010-08-04 00:28:52 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void drawMatches( const Mat& img1, const std::vector<KeyPoint>& keypoints1,
|
|
|
|
const Mat& img2, const std::vector<KeyPoint>& keypoints2,
|
|
|
|
const std::vector<std::vector<DMatch> >& matches1to2, Mat& outImg,
|
2010-08-04 00:28:52 +08:00
|
|
|
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<std::vector<char> >& matchesMask=std::vector<std::vector<char> >(), int flags=DrawMatchesFlags::DEFAULT );
|
2010-06-12 01:15:43 +08:00
|
|
|
|
2010-08-05 20:19:26 +08:00
|
|
|
/****************************************************************************************\
|
2010-09-24 00:17:48 +08:00
|
|
|
* Functions to evaluate the feature detectors and [generic] descriptor extractors *
|
2010-08-05 20:19:26 +08:00
|
|
|
\****************************************************************************************/
|
|
|
|
|
|
|
|
CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<KeyPoint>* keypoints1, std::vector<KeyPoint>* keypoints2,
|
2010-08-05 20:19:26 +08:00
|
|
|
float& repeatability, int& correspCount,
|
|
|
|
const Ptr<FeatureDetector>& fdetector=Ptr<FeatureDetector>() );
|
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void computeRecallPrecisionCurve( const std::vector<std::vector<DMatch> >& matches1to2,
|
|
|
|
const std::vector<std::vector<uchar> >& correctMatches1to2Mask,
|
|
|
|
std::vector<Point2f>& recallPrecisionCurve );
|
2011-05-20 20:14:35 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS float getRecall( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
|
|
|
|
CV_EXPORTS int getNearestPoint( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
|
2010-08-05 20:19:26 +08:00
|
|
|
|
2010-09-24 00:17:48 +08:00
|
|
|
CV_EXPORTS void evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, const Mat& H1to2,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<KeyPoint>& keypoints1, std::vector<KeyPoint>& keypoints2,
|
|
|
|
std::vector<std::vector<DMatch> >* matches1to2, std::vector<std::vector<uchar> >* correctMatches1to2Mask,
|
|
|
|
std::vector<Point2f>& recallPrecisionCurve,
|
2010-10-29 16:44:42 +08:00
|
|
|
const Ptr<GenericDescriptorMatcher>& dmatch=Ptr<GenericDescriptorMatcher>() );
|
2010-08-05 20:19:26 +08:00
|
|
|
|
|
|
|
|
2010-09-24 00:17:48 +08:00
|
|
|
/****************************************************************************************\
|
|
|
|
* Bag of visual words *
|
|
|
|
\****************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Abstract base class for training of a 'bag of visual words' vocabulary from a set of descriptors
|
|
|
|
*/
|
2010-09-30 22:21:22 +08:00
|
|
|
class CV_EXPORTS BOWTrainer
|
2010-09-24 00:17:48 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-11-23 02:27:08 +08:00
|
|
|
BOWTrainer();
|
|
|
|
virtual ~BOWTrainer();
|
2010-10-08 21:17:34 +08:00
|
|
|
|
2010-09-30 22:21:22 +08:00
|
|
|
void add( const Mat& descriptors );
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<Mat>& getDescriptors() const;
|
2010-11-23 02:27:08 +08:00
|
|
|
int descripotorsCount() const;
|
2010-09-30 22:21:22 +08:00
|
|
|
|
|
|
|
virtual void clear();
|
|
|
|
|
2010-09-24 00:17:48 +08:00
|
|
|
/*
|
|
|
|
* Train visual words vocabulary, that is cluster training descriptors and
|
|
|
|
* compute cluster centers.
|
2010-09-30 22:21:22 +08:00
|
|
|
* Returns cluster centers.
|
2010-09-24 00:17:48 +08:00
|
|
|
*
|
|
|
|
* descriptors Training descriptors computed on images keypoints.
|
|
|
|
*/
|
2010-09-30 22:21:22 +08:00
|
|
|
virtual Mat cluster() const = 0;
|
|
|
|
virtual Mat cluster( const Mat& descriptors ) const = 0;
|
|
|
|
|
|
|
|
protected:
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<Mat> descriptors;
|
2010-09-30 22:21:22 +08:00
|
|
|
int size;
|
2010-09-24 00:17:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is BOWTrainer using cv::kmeans to get vocabulary.
|
|
|
|
*/
|
2010-09-30 22:21:22 +08:00
|
|
|
class CV_EXPORTS BOWKMeansTrainer : public BOWTrainer
|
2010-09-24 00:17:48 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
|
|
|
|
int attempts=3, int flags=KMEANS_PP_CENTERS );
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual ~BOWKMeansTrainer();
|
2010-09-30 22:21:22 +08:00
|
|
|
|
|
|
|
// Returns trained vocabulary (i.e. cluster centers).
|
|
|
|
virtual Mat cluster() const;
|
|
|
|
virtual Mat cluster( const Mat& descriptors ) const;
|
2010-09-24 00:17:48 +08:00
|
|
|
|
|
|
|
protected:
|
2010-09-30 22:21:22 +08:00
|
|
|
|
2010-09-24 00:17:48 +08:00
|
|
|
int clusterCount;
|
|
|
|
TermCriteria termcrit;
|
|
|
|
int attempts;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2010-11-14 14:27:48 +08:00
|
|
|
* Class to compute image descriptor using bag of visual words.
|
2010-09-24 00:17:48 +08:00
|
|
|
*/
|
2010-09-30 22:21:22 +08:00
|
|
|
class CV_EXPORTS BOWImgDescriptorExtractor
|
2010-09-24 00:17:48 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
|
|
|
const Ptr<DescriptorMatcher>& dmatcher );
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual ~BOWImgDescriptorExtractor();
|
2010-10-08 21:17:34 +08:00
|
|
|
|
2010-09-30 22:21:22 +08:00
|
|
|
void setVocabulary( const Mat& vocabulary );
|
2010-11-23 02:27:08 +08:00
|
|
|
const Mat& getVocabulary() const;
|
2013-02-25 00:14:01 +08:00
|
|
|
void compute( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& imgDescriptor,
|
|
|
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
|
2010-11-23 02:27:08 +08:00
|
|
|
// compute() is not constant because DescriptorMatcher::match is not constant
|
|
|
|
|
|
|
|
int descriptorSize() const;
|
|
|
|
int descriptorType() const;
|
2010-09-24 00:17:48 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Mat vocabulary;
|
|
|
|
Ptr<DescriptorExtractor> dextractor;
|
|
|
|
Ptr<DescriptorMatcher> dmatcher;
|
|
|
|
};
|
|
|
|
|
2010-08-05 20:19:26 +08:00
|
|
|
} /* namespace cv */
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
#endif
|