From 9213bba48a14a3ab3e9f8db20643b1151253df16 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 20 Apr 2012 17:03:02 +0000 Subject: [PATCH] wrapped Algorithm class. --- modules/core/include/opencv2/core/core.hpp | 35 ++++++++++++++-------- modules/core/src/algorithm.cpp | 35 ++++++++++++++++++++++ modules/python/src2/cv2.cpp | 15 ++++++++++ 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 0440075c5e..12e64a360f 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -4272,7 +4272,7 @@ template struct ParamType {}; /*! Base class for high-level OpenCV algorithms */ -class CV_EXPORTS Algorithm +class CV_EXPORTS_W Algorithm { public: Algorithm(); @@ -4281,13 +4281,22 @@ public: template typename ParamType<_Tp>::member_type get(const string& name) const; template typename ParamType<_Tp>::member_type get(const char* name) const; - void set(const string& name, int value); - void set(const string& name, double value); - void set(const string& name, bool value); - void set(const string& name, const string& value); - void set(const string& name, const Mat& value); - void set(const string& name, const vector& value); - void set(const string& name, const Ptr& value); + + CV_WRAP int getInt(const string& name) const; + CV_WRAP double getDouble(const string& name) const; + CV_WRAP bool getBool(const string& name) const; + CV_WRAP string getString(const string& name) const; + CV_WRAP Mat getMat(const string& name) const; + CV_WRAP vector getMatVector(const string& name) const; + CV_WRAP Ptr getAlgorithm(const string& name) const; + + CV_WRAP_AS(setInt) void set(const string& name, int value); + CV_WRAP_AS(setDouble) void set(const string& name, double value); + CV_WRAP_AS(setBool) void set(const string& name, bool value); + CV_WRAP_AS(setString) void set(const string& name, const string& value); + CV_WRAP_AS(setMat) void set(const string& name, const Mat& value); + CV_WRAP_AS(setMatVector) void set(const string& name, const vector& value); + CV_WRAP_AS(setAlgorithm) void set(const string& name, const Ptr& value); void set(const char* name, int value); void set(const char* name, double value); @@ -4297,10 +4306,10 @@ public: void set(const char* name, const vector& value); void set(const char* name, const Ptr& value); - string paramHelp(const string& name) const; + CV_WRAP string paramHelp(const string& name) const; int paramType(const char* name) const; - int paramType(const string& name) const; - void getParams(vector& names) const; + CV_WRAP int paramType(const string& name) const; + CV_WRAP void getParams(CV_OUT vector& names) const; virtual void write(FileStorage& fs) const; @@ -4310,8 +4319,8 @@ public: typedef int (Algorithm::*Getter)() const; typedef void (Algorithm::*Setter)(int); - static void getList(vector& algorithms); - static Ptr _create(const string& name); + CV_WRAP static void getList(CV_OUT vector& algorithms); + CV_WRAP static Ptr _create(const string& name); template static Ptr<_Tp> create(const string& name); virtual AlgorithmInfo* info() const /* TODO: make it = 0;*/ { return 0; } diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index 65c3fa8b04..6623c27901 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -251,6 +251,41 @@ void Algorithm::set(const char* name, const Ptr& value) info()->set(this, name, ParamType::type, &value); } +int Algorithm::getInt(const string& name) const +{ + return get(name); +} + +double Algorithm::getDouble(const string& name) const +{ + return get(name); +} + +bool Algorithm::getBool(const string& name) const +{ + return get(name); +} + +string Algorithm::getString(const string& name) const +{ + return get(name); +} + +Mat Algorithm::getMat(const string& name) const +{ + return get(name); +} + +vector Algorithm::getMatVector(const string& name) const +{ + return get >(name); +} + +Ptr Algorithm::getAlgorithm(const string& name) const +{ + return get(name); +} + string Algorithm::paramHelp(const string& name) const { return info()->paramHelp(name.c_str()); diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index c84d3c7e27..c2ab6d5d1a 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -86,11 +86,13 @@ typedef vector vector_Rect; typedef vector vector_KeyPoint; typedef vector vector_Mat; typedef vector vector_DMatch; +typedef vector vector_string; typedef vector > vector_vector_Point; typedef vector > vector_vector_Point2f; typedef vector > vector_vector_Point3f; typedef vector > vector_vector_DMatch; +typedef Ptr Ptr_Algorithm; typedef Ptr Ptr_FeatureDetector; typedef Ptr Ptr_DescriptorExtractor; typedef Ptr Ptr_DescriptorMatcher; @@ -759,6 +761,19 @@ template<> struct pyopencvVecConverter } }; +template<> struct pyopencvVecConverter +{ + static bool to(PyObject* obj, vector& value, const char* name="") + { + return pyopencv_to_generic_vec(obj, value, name); + } + + static PyObject* from(const vector& value) + { + return pyopencv_from_generic_vec(value); + } +}; + static inline bool pyopencv_to(PyObject *obj, CvTermCriteria& dst, const char *name="") {