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
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
2014-10-14 03:01:45 +08:00
|
|
|
* Abstract base class for 2D image feature detectors and descriptor extractors
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2014-10-14 03:01:45 +08:00
|
|
|
class CV_EXPORTS_W Feature2D : public virtual Algorithm
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-10-14 03:01:45 +08:00
|
|
|
virtual ~Feature2D();
|
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
|
|
|
*/
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP virtual void detect( InputArray image,
|
|
|
|
CV_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
InputArray mask=noArray() );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-10-16 02:49:17 +08:00
|
|
|
virtual void detect( InputArrayOfArrays images,
|
|
|
|
std::vector<std::vector<KeyPoint> >& keypoints,
|
|
|
|
InputArrayOfArrays masks=noArray() );
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP virtual void compute( InputArray image,
|
|
|
|
CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints,
|
|
|
|
OutputArray descriptors );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-10-16 02:49:17 +08:00
|
|
|
virtual void compute( InputArrayOfArrays images,
|
|
|
|
std::vector<std::vector<KeyPoint> >& keypoints,
|
|
|
|
OutputArrayOfArrays descriptors );
|
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
/* 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 );
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP virtual int descriptorSize() const;
|
|
|
|
CV_WRAP virtual int descriptorType() const;
|
|
|
|
CV_WRAP virtual int defaultNorm() const;
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
// Return true if detector object is empty
|
2012-03-15 22:36:01 +08:00
|
|
|
CV_WRAP virtual bool empty() const;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
typedef Feature2D FeatureDetector;
|
|
|
|
typedef Feature2D DescriptorExtractor;
|
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:
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f);
|
2012-08-23 20:52:01 +08:00
|
|
|
// custom setup
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList,
|
2014-10-16 02:49:17 +08:00
|
|
|
float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>());
|
2012-08-23 20:52:01 +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:
|
2014-10-19 00:44:26 +08:00
|
|
|
enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
|
|
|
|
CV_WRAP virtual int getMaxFeatures() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;
|
|
|
|
CV_WRAP virtual double getScaleFactor() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNLevels(int nlevels) = 0;
|
|
|
|
CV_WRAP virtual int getNLevels() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;
|
|
|
|
CV_WRAP virtual int getEdgeThreshold() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;
|
|
|
|
CV_WRAP virtual int getFirstLevel() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setWTA_K(int wta_k) = 0;
|
|
|
|
CV_WRAP virtual int getWTA_K() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setScoreType(int scoreType) = 0;
|
|
|
|
CV_WRAP virtual int getScoreType() const = 0;
|
2010-06-04 13:30:09 +08:00
|
|
|
|
2014-10-19 00:44:26 +08:00
|
|
|
CV_WRAP virtual void setPatchSize(int patchSize) = 0;
|
|
|
|
CV_WRAP virtual int getPatchSize() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;
|
|
|
|
CV_WRAP virtual int getFastThreshold() const = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2014-10-14 03:01:45 +08:00
|
|
|
class CV_EXPORTS_W MSER : public Feature2D
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-15 22:36:01 +08:00
|
|
|
//! the full constructor
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP static Ptr<MSER> create( 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
|
|
|
|
2014-10-17 01:59:38 +08:00
|
|
|
CV_WRAP virtual void detectRegions( InputArray image,
|
|
|
|
std::vector<std::vector<Point> >& msers,
|
|
|
|
std::vector<Rect>& bboxes ) = 0;
|
2014-10-19 00:44:26 +08:00
|
|
|
|
|
|
|
CV_WRAP virtual void setDelta(int delta) = 0;
|
|
|
|
CV_WRAP virtual int getDelta() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setMinArea(int minArea) = 0;
|
|
|
|
CV_WRAP virtual int getMinArea() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setMaxArea(int maxArea) = 0;
|
|
|
|
CV_WRAP virtual int getMaxArea() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setPass2Only(bool f) = 0;
|
|
|
|
CV_WRAP virtual bool getPass2Only() const = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
2012-05-29 18:36:19 +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,
|
2014-03-11 21:20:01 +08:00
|
|
|
int threshold, bool nonmaxSuppression=true );
|
2012-08-28 22:15:14 +08:00
|
|
|
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
|
2014-03-11 21:20:01 +08:00
|
|
|
int threshold, bool nonmaxSuppression, int type );
|
2012-03-15 22:36:01 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
class CV_EXPORTS_W FastFeatureDetector : public Feature2D
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-10-17 00:58:29 +08:00
|
|
|
enum
|
2012-07-31 21:17:58 +08:00
|
|
|
{
|
2014-10-17 00:58:29 +08:00
|
|
|
TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2,
|
|
|
|
THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002,
|
2012-07-31 21:17:58 +08:00
|
|
|
};
|
|
|
|
|
2014-10-16 02:49:17 +08:00
|
|
|
CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10,
|
|
|
|
bool nonmaxSuppression=true,
|
|
|
|
int type=FastFeatureDetector::TYPE_9_16 );
|
2014-10-19 00:44:26 +08:00
|
|
|
|
|
|
|
CV_WRAP virtual void setThreshold(int threshold) = 0;
|
|
|
|
CV_WRAP virtual int getThreshold() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
|
|
|
|
CV_WRAP virtual bool getNonmaxSuppression() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setType(int type) = 0;
|
|
|
|
CV_WRAP virtual int getType() const = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2012-03-15 22:36:01 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
class CV_EXPORTS_W GFTTDetector : public Feature2D
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-10-14 03:01:45 +08:00
|
|
|
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 );
|
2014-10-19 00:44:26 +08:00
|
|
|
CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
|
|
|
|
CV_WRAP virtual int getMaxFeatures() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setQualityLevel(double qlevel) = 0;
|
|
|
|
CV_WRAP virtual double getQualityLevel() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setMinDistance(double minDistance) = 0;
|
|
|
|
CV_WRAP virtual double getMinDistance() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setBlockSize(int blockSize) = 0;
|
|
|
|
CV_WRAP virtual int getBlockSize() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setHarrisDetector(bool val) = 0;
|
|
|
|
CV_WRAP virtual bool getHarrisDetector() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setK(double k) = 0;
|
|
|
|
CV_WRAP virtual double getK() const = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
};
|
|
|
|
|
2011-05-21 06:25:53 +08:00
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
|
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
|
|
|
};
|
|
|
|
|
2014-10-14 03:01:45 +08:00
|
|
|
CV_WRAP static Ptr<SimpleBlobDetector>
|
|
|
|
create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
|
2010-12-27 17:15:08 +08:00
|
|
|
};
|
|
|
|
|
2012-05-29 18:36:19 +08:00
|
|
|
|
2014-04-05 15:25:46 +08:00
|
|
|
/*!
|
|
|
|
KAZE implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W KAZE : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
2014-10-14 03:01:45 +08:00
|
|
|
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,
|
2014-10-19 00:44:26 +08:00
|
|
|
int nOctaves = 4, int nOctaveLayers = 4,
|
2014-10-14 03:01:45 +08:00
|
|
|
int diffusivity = KAZE::DIFF_PM_G2);
|
2014-10-19 00:44:26 +08:00
|
|
|
|
|
|
|
CV_WRAP virtual void setExtended(bool extended) = 0;
|
|
|
|
CV_WRAP virtual bool getExtended() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setUpright(bool upright) = 0;
|
|
|
|
CV_WRAP virtual bool getUpright() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setThreshold(double threshold) = 0;
|
|
|
|
CV_WRAP virtual double getThreshold() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNOctaves(int octaves) = 0;
|
|
|
|
CV_WRAP virtual int getNOctaves() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
|
|
|
|
CV_WRAP virtual int getNOctaveLayers() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setDiffusivity(int diff) = 0;
|
|
|
|
CV_WRAP virtual int getDiffusivity() const = 0;
|
2014-04-05 15:25:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
AKAZE implementation
|
|
|
|
*/
|
|
|
|
class CV_EXPORTS_W AKAZE : public Feature2D
|
|
|
|
{
|
|
|
|
public:
|
2014-10-14 03:01:45 +08:00
|
|
|
// 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
|
|
|
|
};
|
2014-04-05 15:25:46 +08:00
|
|
|
|
2014-10-16 02:49:17 +08:00
|
|
|
CV_WRAP static Ptr<AKAZE> create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB,
|
2014-10-14 03:01:45 +08:00
|
|
|
int descriptor_size = 0, int descriptor_channels = 3,
|
2014-10-19 00:44:26 +08:00
|
|
|
float threshold = 0.001f, int nOctaves = 4,
|
|
|
|
int nOctaveLayers = 4, int diffusivity = KAZE::DIFF_PM_G2);
|
|
|
|
|
|
|
|
CV_WRAP virtual void setDescriptorType(int dtype) = 0;
|
|
|
|
CV_WRAP virtual int getDescriptorType() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setDescriptorSize(int dsize) = 0;
|
|
|
|
CV_WRAP virtual int getDescriptorSize() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setDescriptorChannels(int dch) = 0;
|
|
|
|
CV_WRAP virtual int getDescriptorChannels() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setThreshold(double threshold) = 0;
|
|
|
|
CV_WRAP virtual double getThreshold() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNOctaves(int octaves) = 0;
|
|
|
|
CV_WRAP virtual int getNOctaves() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
|
|
|
|
CV_WRAP virtual int getNOctaveLayers() const = 0;
|
|
|
|
|
|
|
|
CV_WRAP virtual void setDiffusivity(int diff) = 0;
|
|
|
|
CV_WRAP virtual int getDiffusivity() const = 0;
|
2014-04-05 15:25:46 +08:00
|
|
|
};
|
2014-10-14 03:01:45 +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
|
|
|
|
2013-07-25 23:40:08 +08:00
|
|
|
template<int cellsize> struct HammingMultilevel
|
2011-11-08 20:01:49 +08:00
|
|
|
{
|
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
|
|
|
*/
|
2014-01-15 14:01:40 +08:00
|
|
|
CV_WRAP virtual void add( InputArrayOfArrays 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).
|
2013-12-27 17:04:02 +08:00
|
|
|
CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors,
|
2014-01-24 23:39:05 +08:00
|
|
|
CV_OUT std::vector<DMatch>& matches, InputArray mask=noArray() ) 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.
|
2013-12-27 17:04:02 +08:00
|
|
|
CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
2013-02-25 00:14:01 +08:00
|
|
|
CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArray mask=noArray(), 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).
|
2013-12-27 17:04:02 +08:00
|
|
|
void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArray mask=noArray(), 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-12-27 17:04:02 +08:00
|
|
|
CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector<DMatch>& matches,
|
2014-02-17 07:00:20 +08:00
|
|
|
InputArrayOfArrays masks=noArray() );
|
2013-12-27 17:04:02 +08:00
|
|
|
CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
2014-02-17 07:00:20 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
2013-12-27 17:04:02 +08:00
|
|
|
void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2014-02-17 07:00:20 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), 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-12-27 17:04:02 +08:00
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
|
2013-12-27 17:04:02 +08:00
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
|
2010-06-16 16:56:53 +08:00
|
|
|
|
2014-02-17 07:00:20 +08:00
|
|
|
static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx );
|
|
|
|
static bool isMaskedOut( InputArrayOfArrays 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(); }
|
2014-02-17 07:00:20 +08:00
|
|
|
void checkMasks( InputArrayOfArrays 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;
|
2013-12-27 17:04:02 +08:00
|
|
|
std::vector<UMat> utrainDescCollection;
|
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
|
|
|
protected:
|
2013-12-27 17:04:02 +08:00
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
2013-12-27 17:04:02 +08:00
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), 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:
|
2013-08-13 21:30:14 +08:00
|
|
|
CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
|
|
|
|
const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2014-02-17 05:37:32 +08:00
|
|
|
virtual void add( InputArrayOfArrays 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;
|
|
|
|
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-12-27 17:04:02 +08:00
|
|
|
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), bool compactResult=false );
|
2013-12-27 17:04:02 +08:00
|
|
|
virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
2014-01-24 23:39:05 +08:00
|
|
|
InputArrayOfArrays masks=noArray(), 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-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.
|
2014-02-05 14:55:26 +08:00
|
|
|
CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray 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.
|
2014-02-04 20:34:18 +08:00
|
|
|
CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
|
|
|
|
InputArray img2, const std::vector<KeyPoint>& keypoints2,
|
2014-02-05 14:55:26 +08:00
|
|
|
const std::vector<DMatch>& matches1to2, InputOutputArray 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
|
|
|
|
2014-02-04 20:34:18 +08:00
|
|
|
CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
|
|
|
|
InputArray img2, const std::vector<KeyPoint>& keypoints2,
|
2014-02-05 14:55:26 +08:00
|
|
|
const std::vector<std::vector<DMatch> >& matches1to2, InputOutputArray 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
|
|
|
/****************************************************************************************\
|
|
|
|
* Bag of visual words *
|
|
|
|
\****************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Abstract base class for training of a 'bag of visual words' vocabulary from a set of descriptors
|
|
|
|
*/
|
2014-07-08 18:33:56 +08:00
|
|
|
class CV_EXPORTS_W 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
|
|
|
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP void add( const Mat& descriptors );
|
|
|
|
CV_WRAP const std::vector<Mat>& getDescriptors() const;
|
|
|
|
CV_WRAP int descriptorsCount() const;
|
2010-09-30 22:21:22 +08:00
|
|
|
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP virtual void clear();
|
2010-09-30 22:21:22 +08:00
|
|
|
|
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.
|
|
|
|
*/
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP virtual Mat cluster() const = 0;
|
|
|
|
CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0;
|
2010-09-30 22:21:22 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-07-08 18:33:56 +08:00
|
|
|
class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer
|
2010-09-24 00:17:48 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
|
2010-09-24 00:17:48 +08:00
|
|
|
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).
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP virtual Mat cluster() const;
|
|
|
|
CV_WRAP 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
|
|
|
*/
|
2014-07-08 18:33:56 +08:00
|
|
|
class CV_EXPORTS_W BOWImgDescriptorExtractor
|
2010-09-24 00:17:48 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
|
2010-09-24 00:17:48 +08:00
|
|
|
const Ptr<DescriptorMatcher>& dmatcher );
|
2013-09-05 12:05:54 +08:00
|
|
|
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
|
2010-11-23 02:27:08 +08:00
|
|
|
virtual ~BOWImgDescriptorExtractor();
|
2010-10-08 21:17:34 +08:00
|
|
|
|
2014-07-08 18:33:56 +08:00
|
|
|
CV_WRAP void setVocabulary( const Mat& vocabulary );
|
|
|
|
CV_WRAP const Mat& getVocabulary() const;
|
2014-02-05 17:51:14 +08:00
|
|
|
void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray imgDescriptor,
|
2013-02-25 00:14:01 +08:00
|
|
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
|
2014-02-05 17:51:14 +08:00
|
|
|
void compute( InputArray keypointDescriptors, OutputArray imgDescriptor,
|
2013-09-05 12:05:54 +08:00
|
|
|
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
|
2010-11-23 02:27:08 +08:00
|
|
|
// compute() is not constant because DescriptorMatcher::match is not constant
|
|
|
|
|
2014-07-08 18:33:56 +08:00
|
|
|
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;
|
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
|