From df6a95ed8786ad5af899efaf841f065ad05bf9f0 Mon Sep 17 00:00:00 2001 From: Ilya Lysenkov Date: Mon, 12 Mar 2012 11:39:48 +0000 Subject: [PATCH] Wraped SimpleBlobDetector for Python --- .../include/opencv2/features2d/features2d.hpp | 38 +++++++++---------- modules/python/src2/cv2.cpp | 15 ++++++++ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 91172cb68..20cc81217 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -1552,38 +1552,38 @@ private: mutable ORB orb_; }; -class CV_EXPORTS SimpleBlobDetector : public cv::FeatureDetector +class CV_EXPORTS_W SimpleBlobDetector : public FeatureDetector { public: - struct CV_EXPORTS Params + struct CV_EXPORTS_W_SIMPLE Params { - Params(); - float thresholdStep; - float minThreshold; - float maxThreshold; - size_t minRepeatability; - float minDistBetweenBlobs; + 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; - bool filterByColor; - uchar blobColor; + CV_PROP_RW bool filterByColor; + CV_PROP_RW uchar blobColor; - bool filterByArea; - float minArea, maxArea; + CV_PROP_RW bool filterByArea; + CV_PROP_RW float minArea, maxArea; - bool filterByCircularity; - float minCircularity, maxCircularity; + CV_PROP_RW bool filterByCircularity; + CV_PROP_RW float minCircularity, maxCircularity; - bool filterByInertia; - float minInertiaRatio, maxInertiaRatio; + CV_PROP_RW bool filterByInertia; + CV_PROP_RW float minInertiaRatio, maxInertiaRatio; - bool filterByConvexity; - float minConvexity, maxConvexity; + CV_PROP_RW bool filterByConvexity; + CV_PROP_RW float minConvexity, maxConvexity; void read( const FileNode& fn ); void write( FileStorage& fs ) const; }; - SimpleBlobDetector(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params()); + CV_WRAP SimpleBlobDetector(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params()); virtual void read( const FileNode& fn ); virtual void write( FileStorage& fs ) const; diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index dff5a35a5..b50eb2d79 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -87,6 +87,8 @@ typedef Ptr Ptr_FeatureDetector; typedef Ptr Ptr_DescriptorExtractor; typedef Ptr Ptr_DescriptorMatcher; +typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; + typedef cvflann::flann_distance_t cvflann_flann_distance_t; typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t; typedef Ptr Ptr_flann_IndexParams; @@ -357,6 +359,19 @@ static bool pyopencv_to(PyObject* obj, int& value, const char* name = " return value != -1 || !PyErr_Occurred(); } +static PyObject* pyopencv_from(uchar value) +{ + return PyInt_FromLong(value); +} + +static bool pyopencv_to(PyObject* obj, uchar& value, const char* name = "") +{ + if(!obj || obj == Py_None) + return true; + value = (int)PyInt_AsLong(obj); + return value != -1 || !PyErr_Occurred(); +} + static PyObject* pyopencv_from(double value) { return PyFloat_FromDouble(value);