From 028c44531f502d55ab3a064d2556a69892458c8f Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Thu, 15 Sep 2011 11:10:06 +0000 Subject: [PATCH] wrapped FlannBasedMatcher (and extended DescriptorMatcher wrapper) updated feature_homography.py sample to use new features --- .../include/opencv2/features2d/features2d.hpp | 20 +++---- modules/python/src2/cv2.cpp | 13 +++++ modules/python/src2/hdr_parser.py | 2 +- samples/python2/feature_homography.py | 54 +++++++++++++------ 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 5a2c3015e8..a62b4ed0b3 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -2237,24 +2237,24 @@ public: * Add descriptors to train descriptor collection. * descriptors Descriptors to add. Each descriptors[i] is a descriptors set from one image. */ - virtual void add( const vector& descriptors ); + CV_WRAP virtual void add( const vector& descriptors ); /* * Get train descriptors collection. */ - const vector& getTrainDescriptors() const; + CV_WRAP const vector& getTrainDescriptors() const; /* * Clear train descriptors collection. */ - virtual void clear(); + CV_WRAP virtual void clear(); /* * Return true if there are not train descriptors in collection. */ - virtual bool empty() const; + CV_WRAP virtual bool empty() const; /* * Return true if the matcher supports mask in match methods. */ - virtual bool isMaskSupported() const = 0; + CV_WRAP virtual bool isMaskSupported() const = 0; /* * Train matcher (e.g. train flann index). @@ -2267,7 +2267,7 @@ public: * if it has not trained yet or if new descriptors have been added to the train * collection). */ - virtual void train(); + CV_WRAP virtual void train(); /* * Group of methods to match descriptors from image pair. * Method train() is run in this methods. @@ -2291,9 +2291,9 @@ public: * Group of methods to match descriptors from one image to image set. * See description of similar methods for matching image pair above. */ - void match( const Mat& queryDescriptors, vector& matches, + CV_WRAP void match( const Mat& queryDescriptors, CV_OUT vector& matches, const vector& masks=vector() ); - void knnMatch( const Mat& queryDescriptors, vector >& matches, int k, + CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT vector >& matches, int k, const vector& masks=vector(), bool compactResult=false ); void radiusMatch( const Mat& queryDescriptors, vector >& matches, float maxDistance, const vector& masks=vector(), bool compactResult=false ); @@ -2562,10 +2562,10 @@ void BruteForceMatcher >::radiusMatchImpl( const Mat& queryDescriptors /* * Flann based matcher */ -class CV_EXPORTS FlannBasedMatcher : public DescriptorMatcher +class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher { public: - FlannBasedMatcher( const Ptr& indexParams=new flann::KDTreeIndexParams(), + CV_WRAP FlannBasedMatcher( const Ptr& indexParams=new flann::KDTreeIndexParams(), const Ptr& searchParams=new flann::SearchParams() ); virtual void add( const vector& descriptors ); diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 0dc07c29d8..b4e4611eed 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -74,6 +74,11 @@ typedef Ptr Ptr_FeatureDetector; typedef Ptr Ptr_DescriptorExtractor; typedef Ptr Ptr_DescriptorMatcher; +typedef cvflann::flann_distance_t cvflann_flann_distance_t; +typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t; +typedef Ptr Ptr_flann_IndexParams; +typedef Ptr Ptr_flann_SearchParams; + static PyObject* failmsgp(const char *fmt, ...) { char str[1000]; @@ -820,6 +825,14 @@ static bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name return ok; } +template +static bool pyopencv_to(PyObject *o, Ptr& p, const char *name="") +{ + p = new T(); + return pyopencv_to(o, *p, name); +} + + static bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name="") { int d = (int)dist; diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index fa4c177dfb..48db3e32be 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -191,7 +191,7 @@ class CppHeaderParser(object): if add_star: arg_type += "*" - arg_type = self.batch_replace(arg_type, [("std::", ""), ("cv::", "")]) + arg_type = self.batch_replace(arg_type, [("std::", ""), ("cv::", ""), ("::", "_")]) return arg_type, arg_name, modlist, argno diff --git a/samples/python2/feature_homography.py b/samples/python2/feature_homography.py index 00e72d4c02..469fb10e5b 100644 --- a/samples/python2/feature_homography.py +++ b/samples/python2/feature_homography.py @@ -4,35 +4,53 @@ Feature homography Example of using features2d framework for interactive video homography matching. +Usage +----- +feature_homography.py [