Common Interfaces of Generic Descriptor Matchers ================================================ .. highlight:: cpp Matchers of keypoint descriptors in OpenCV have wrappers with common interface that enables to switch easily between different algorithms solving the same problem. This section is devoted to matching descriptors that can not be represented as vectors in a multidimensional space. ``GenericDescriptorMatcher`` is a more generic interface for descriptors. It does not make any assumptions about descriptor representation. Every descriptor with :func:`DescriptorExtractor` interface has a wrapper with ``GenericDescriptorMatcher`` interface (see :func:`VectorDescriptorMatcher` ). There are descriptors such as One way descriptor and Ferns that have ``GenericDescriptorMatcher`` interface implemented, but do not support :func:`DescriptorExtractor` . .. index:: GenericDescriptorMatcher .. _GenericDescriptorMatcher: GenericDescriptorMatcher ------------------------ `id=0.0985891324868 Comments from the Wiki `__ .. ctype:: GenericDescriptorMatcher Abstract interface for a keypoint descriptor extracting and matching. There is :func:`DescriptorExtractor` and :func:`DescriptorMatcher` for these purposes too, but their interfaces are intended for descriptors represented as vectors in a multidimensional space. ``GenericDescriptorMatcher`` is a more generic interface for descriptors. As :func:`DescriptorMatcher` , ``GenericDescriptorMatcher`` has two groups of match methods: for matching keypoints of one image with other image or with image set. :: class GenericDescriptorMatcher { public: GenericDescriptorMatcher(); virtual ~GenericDescriptorMatcher(); virtual void add( const vector& images, vector >& keypoints ); const vector& getTrainImages() const; const vector >& getTrainKeypoints() const; virtual void clear(); virtual void train() = 0; virtual bool isMaskSupported() = 0; void classify( const Mat& queryImage, vector& queryKeypoints, const Mat& trainImage, vector& trainKeypoints ) const; void classify( const Mat& queryImage, vector& queryKeypoints ); /* * Group of methods to match keypoints from image pair. */ void match( const Mat& queryImage, vector& queryKeypoints, const Mat& trainImage, vector& trainKeypoints, vector& matches, const Mat& mask=Mat() ) const; void knnMatch( const Mat& queryImage, vector& queryKeypoints, const Mat& trainImage, vector& trainKeypoints, vector >& matches, int k, const Mat& mask=Mat(), bool compactResult=false ) const; void radiusMatch( const Mat& queryImage, vector& queryKeypoints, const Mat& trainImage, vector& trainKeypoints, vector >& matches, float maxDistance, const Mat& mask=Mat(), bool compactResult=false ) const; /* * Group of methods to match keypoints from one image to image set. */ void match( const Mat& queryImage, vector& queryKeypoints, vector& matches, const vector& masks=vector() ); void knnMatch( const Mat& queryImage, vector& queryKeypoints, vector >& matches, int k, const vector& masks=vector(), bool compactResult=false ); void radiusMatch( const Mat& queryImage, vector& queryKeypoints, vector >& matches, float maxDistance, const vector& masks=vector(), bool compactResult=false ); virtual void read( const FileNode& ); virtual void write( FileStorage& ) const; virtual Ptr clone( bool emptyTrainData=false ) const = 0; protected: ... }; .. .. index:: GenericDescriptorMatcher::add cv::GenericDescriptorMatcher::add --------------------------------- `id=0.997977617828 Comments from the Wiki `__ .. cfunction:: void GenericDescriptorMatcher::add( const vector\& images, vector >\& keypoints ) Adds images and keypoints from them to the train collection (descriptors are supposed to be calculated here). If train collection is not empty new image and keypoints from them will be added to existing data. :param images: Image collection. :param keypoints: Point collection. Assumes that ``keypoints[i]`` are keypoints detected in an image ``images[i]`` . .. index:: GenericDescriptorMatcher::getTrainImages cv::GenericDescriptorMatcher::getTrainImages -------------------------------------------- `id=0.416380012112 Comments from the Wiki `__ :: .. .. index:: cv:: ---- `id=0.701405481042 Comments from the Wiki `__ :: .. .. index:: cv:: ---- `id=0.653057551742 Comments from the Wiki `__ :: .. .. index:: cv:: ---- `id=0.631382938188 Comments from the Wiki `__ :: .. .. index:: cv:: ---- `id=0.508874889278 Comments from the Wiki `__ :: .. .. index:: cv:: ---- `id=0.427993929677 Comments from the Wiki `__ :func:`GenericDescriptorMatcher::add` .. cfunction:: void GenericDescriptorMatcher::classify( const Mat\& queryImage, vector\& queryKeypoints, const Mat\& trainImage, vector\& trainKeypoints ) const Classifies query keypoints under keypoints of one train image qiven as input argument (first version of the method) or train image collection that set using (second version). .. cfunction:: void GenericDescriptorMatcher::classify( const Mat\& queryImage, vector\& queryKeypoints ) :param queryImage: The query image. :param queryKeypoints: Keypoints from the query image. :param trainImage: The train image. :param trainKeypoints: Keypoints from the train image. .. index:: GenericDescriptorMatcher::match cv::GenericDescriptorMatcher::match ----------------------------------- `id=0.330085498001 Comments from the Wiki `__ :func:`GenericDescriptorMatcher::add` :func:`DescriptorMatcher::match` .. cfunction:: void GenericDescriptorMatcher::match( const Mat\& queryImage, vector\& queryKeypoints, const Mat\& trainImage, vector\& trainKeypoints, vector\& matches, const Mat\& mask=Mat() ) const Find best match for query keypoints to the training set. In first version of method one train image and keypoints detected on it - are input arguments. In second version query keypoints are matched to training collectin that set using . As in the mask can be set. .. cfunction:: void GenericDescriptorMatcher::match( const Mat\& queryImage, vector\& queryKeypoints, vector\& matches, const vector\& masks=vector() ) :param queryImage: Query image. :param queryKeypoints: Keypoints detected in ``queryImage`` . :param trainImage: Train image. This will not be added to train image collection stored in class object. :param trainKeypoints: Keypoints detected in ``trainImage`` . They will not be added to train points collection stored in class object. :param matches: Matches. If some query descriptor (keypoint) masked out in ``mask`` no match will be added for this descriptor. So ``matches`` size may be less query keypoints count. :param mask: Mask specifying permissible matches between input query and train keypoints. :param masks: The set of masks. Each ``masks[i]`` specifies permissible matches between input query keypoints and stored train keypointss from i-th image. .. index:: GenericDescriptorMatcher::knnMatch cv::GenericDescriptorMatcher::knnMatch -------------------------------------- `id=0.418861771415 Comments from the Wiki `__ :func:`GenericDescriptorMatcher::match` :func:`DescriptorMatcher::knnMatch` .. cfunction:: void GenericDescriptorMatcher::knnMatch( const Mat\& queryImage, vector\& queryKeypoints, const Mat\& trainImage, vector\& trainKeypoints, vector >\& matches, int k, const Mat\& mask=Mat(), bool compactResult=false ) const Find the knn best matches for each keypoint from a query set with train keypoints. Found knn (or less if not possible) matches are returned in distance increasing order. Details see in and . .. cfunction:: void GenericDescriptorMatcher::knnMatch( const Mat\& queryImage, vector\& queryKeypoints, vector >\& matches, int k, const vector\& masks=vector(), bool compactResult=false ) .. index:: GenericDescriptorMatcher::radiusMatch cv::GenericDescriptorMatcher::radiusMatch ----------------------------------------- `id=0.244054169091 Comments from the Wiki `__ :func:`GenericDescriptorMatcher::match` :func:`DescriptorMatcher::radiusMatch` .. cfunction:: void GenericDescriptorMatcher::radiusMatch( const Mat\& queryImage, vector\& queryKeypoints, const Mat\& trainImage, vector\& trainKeypoints, vector >\& matches, float maxDistance, const Mat\& mask=Mat(), bool compactResult=false ) const Find the best matches for each query keypoint which have distance less than given threshold. Found matches are returned in distance increasing order. Details see in and . .. cfunction:: void GenericDescriptorMatcher::radiusMatch( const Mat\& queryImage, vector\& queryKeypoints, vector >\& matches, float maxDistance, const vector\& masks=vector(), bool compactResult=false ) .. index:: GenericDescriptorMatcher::read cv::GenericDescriptorMatcher::read ---------------------------------- `id=0.403710427903 Comments from the Wiki `__ .. cfunction:: void GenericDescriptorMatcher::read( const FileNode\& fn ) Reads matcher object from a file node. .. index:: GenericDescriptorMatcher::write cv::GenericDescriptorMatcher::write ----------------------------------- `id=0.181230872136 Comments from the Wiki `__ .. cfunction:: void GenericDescriptorMatcher::write( FileStorage\& fs ) const Writes match object to a file storage .. index:: GenericDescriptorMatcher::clone cv::GenericDescriptorMatcher::clone ----------------------------------- `id=0.961650717058 Comments from the Wiki `__ .. cfunction:: Ptr\\GenericDescriptorMatcher::clone( bool emptyTrainData ) const Clone the matcher. :param emptyTrainData: 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. .. index:: OneWayDescriptorMatcher .. _OneWayDescriptorMatcher: OneWayDescriptorMatcher ----------------------- `id=0.490660931594 Comments from the Wiki `__ .. ctype:: OneWayDescriptorMatcher Wrapping class for computing, matching and classification of descriptors using :func:`OneWayDescriptorBase` class. :: class OneWayDescriptorMatcher : public GenericDescriptorMatcher { public: class Params { public: static const int POSE_COUNT = 500; static const int PATCH_WIDTH = 24; static const int PATCH_HEIGHT = 24; static float GET_MIN_SCALE() { return 0.7f; } static float GET_MAX_SCALE() { return 1.5f; } static float GET_STEP_SCALE() { return 1.2f; } Params( int poseCount = POSE_COUNT, Size patchSize = Size(PATCH_WIDTH, PATCH_HEIGHT), string pcaFilename = string(), string trainPath = string(), string trainImagesList = string(), float minScale = GET_MIN_SCALE(), float maxScale = GET_MAX_SCALE(), float stepScale = GET_STEP_SCALE() ); int poseCount; Size patchSize; string pcaFilename; string trainPath; string trainImagesList; float minScale, maxScale, stepScale; }; OneWayDescriptorMatcher( const Params& params=Params() ); virtual ~OneWayDescriptorMatcher(); void initialize( const Params& params, const Ptr& base=Ptr() ); // Clears keypoints storing in collection and OneWayDescriptorBase virtual void clear(); virtual void train(); virtual bool isMaskSupported(); virtual void read( const FileNode &fn ); virtual void write( FileStorage& fs ) const; virtual Ptr clone( bool emptyTrainData=false ) const; protected: ... }; .. .. index:: FernDescriptorMatcher .. _FernDescriptorMatcher: FernDescriptorMatcher --------------------- `id=0.491113993201 Comments from the Wiki `__ .. ctype:: FernDescriptorMatcher Wrapping class for computing, matching and classification of descriptors using :func:`FernClassifier` class. :: class FernDescriptorMatcher : public GenericDescriptorMatcher { public: class Params { public: Params( int nclasses=0, int patchSize=FernClassifier::PATCH_SIZE, int signatureSize=FernClassifier::DEFAULT_SIGNATURE_SIZE, int nstructs=FernClassifier::DEFAULT_STRUCTS, int structSize=FernClassifier::DEFAULT_STRUCT_SIZE, int nviews=FernClassifier::DEFAULT_VIEWS, int compressionMethod=FernClassifier::COMPRESSION_NONE, const PatchGenerator& patchGenerator=PatchGenerator() ); Params( const string& filename ); int nclasses; int patchSize; int signatureSize; int nstructs; int structSize; int nviews; int compressionMethod; PatchGenerator patchGenerator; string filename; }; FernDescriptorMatcher( const Params& params=Params() ); virtual ~FernDescriptorMatcher(); virtual void clear(); virtual void train(); virtual bool isMaskSupported(); virtual void read( const FileNode &fn ); virtual void write( FileStorage& fs ) const; virtual Ptr clone( bool emptyTrainData=false ) const; protected: ... }; .. .. index:: VectorDescriptorMatcher .. _VectorDescriptorMatcher: VectorDescriptorMatcher ----------------------- `id=0.935264431752 Comments from the Wiki `__ .. ctype:: VectorDescriptorMatcher Class used for matching descriptors that can be described as vectors in a finite-dimensional space. :: class CV_EXPORTS VectorDescriptorMatcher : public GenericDescriptorMatcher { public: VectorDescriptorMatcher( const Ptr& extractor, const Ptr& matcher ); virtual ~VectorDescriptorMatcher(); virtual void add( const vector& imgCollection, vector >& pointCollection ); virtual void clear(); virtual void train(); virtual bool isMaskSupported(); virtual void read( const FileNode& fn ); virtual void write( FileStorage& fs ) const; virtual Ptr clone( bool emptyTrainData=false ) const; protected: ... }; .. Example of creating: :: VectorDescriptorMatcher matcher( new SurfDescriptorExtractor, new BruteForceMatcher > ); ..