From a51a8ad577b54d0d0991862b6209d0856f3a192a Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Sun, 14 Aug 2011 19:46:39 +0000 Subject: [PATCH] fixed tickets #1301, #1303, #1305 --- modules/features2d/src/matchers.cpp | 4 ++-- .../flann/include/opencv2/flann/miniflann.hpp | 4 ++-- modules/flann/src/miniflann.cpp | 9 +++++--- .../include/opencv2/objdetect/objdetect.hpp | 10 ++++----- modules/objdetect/src/hog.cpp | 4 ++-- modules/python/src2/cv2.cpp | 22 +++++++++++++++---- modules/python/src2/gen2.py | 6 ++--- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 795cc1afeb..2a6c66885c 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -616,7 +616,7 @@ void FlannBasedMatcher::read( const FileNode& fn) indexParams->setBool(name, (int) ip[i]["value"]); break; case CV_MAKETYPE(CV_USRTYPE1,3): - indexParams->setAlgorithm(name, (int) ip[i]["value"]); + indexParams->setAlgorithm((int) ip[i]["value"]); break; }; } @@ -655,7 +655,7 @@ void FlannBasedMatcher::read( const FileNode& fn) searchParams->setBool(name, (int) ip[i]["value"]); break; case CV_MAKETYPE(CV_USRTYPE1,3): - searchParams->setAlgorithm(name, (int) ip[i]["value"]); + searchParams->setAlgorithm((int) ip[i]["value"]); break; }; } diff --git a/modules/flann/include/opencv2/flann/miniflann.hpp b/modules/flann/include/opencv2/flann/miniflann.hpp index b36cba1326..9c3c36e5a3 100644 --- a/modules/flann/include/opencv2/flann/miniflann.hpp +++ b/modules/flann/include/opencv2/flann/miniflann.hpp @@ -53,8 +53,8 @@ namespace cv namespace flann { - using namespace cvflann; +using namespace cvflann; struct CV_EXPORTS IndexParams { @@ -70,7 +70,7 @@ struct CV_EXPORTS IndexParams void setDouble(const std::string& key, double value); void setFloat(const std::string& key, float value); void setBool(const std::string& key, bool value); - void setAlgorithm(const std::string& key, int value); + void setAlgorithm(int value); void getAll(std::vector& names, std::vector& types, diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp index 54f3c9faac..d26c3b9732 100644 --- a/modules/flann/src/miniflann.cpp +++ b/modules/flann/src/miniflann.cpp @@ -81,9 +81,9 @@ void IndexParams::setBool(const std::string& key, bool value) setParam(*this, key, value); } -void IndexParams::setAlgorithm(const std::string& key, int value) +void IndexParams::setAlgorithm(int value) { - setParam(*this, key, (cvflann::flann_algorithm_t)value); + setParam(*this, "algorithm", (cvflann::flann_algorithm_t)value); } void IndexParams::getAll(std::vector& names, @@ -293,7 +293,10 @@ template void buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Distance& dist = Distance()) { typedef typename Distance::ElementType ElementType; - CV_Assert(DataType::type == data.type() && data.isContinuous()); + if(DataType::type != data.type()) + CV_Error_(CV_StsUnsupportedFormat, ("type=%d\n", data.type())); + if(!data.isContinuous()) + CV_Error(CV_StsBadArg, "Only continuous arrays are supported"); ::cvflann::Matrix dataset((ElementType*)data.data, data.rows, data.cols); IndexType* _index = new IndexType(dataset, get_params(params), dist); diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index aa6ed24531..6f8643e086 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -286,8 +286,9 @@ namespace cv ///////////////////////////// Object Detection //////////////////////////// -CV_EXPORTS_W void groupRectangles(CV_IN_OUT vector& rectList, int groupThreshold, double eps=0.2); -CV_EXPORTS_W void groupRectangles(CV_IN_OUT vector& rectList, CV_OUT vector& weights, int groupThreshold, double eps=0.2); +CV_EXPORTS void groupRectangles(CV_OUT CV_IN_OUT vector& rectList, int groupThreshold, double eps=0.2); +CV_EXPORTS_W void groupRectangles(CV_OUT CV_IN_OUT vector& rectList, CV_OUT vector& weights, int groupThreshold, double eps=0.2); +CV_EXPORTS void groupRectangles( vector& rectList, int groupThreshold, double eps, vector* weights, vector* levelWeights ); CV_EXPORTS void groupRectangles(vector& rectList, vector& rejectLevels, vector& levelWeights, int groupThreshold, double eps=0.2); CV_EXPORTS void groupRectangles_meanshift(vector& rectList, vector& foundWeights, vector& foundScales, @@ -430,8 +431,7 @@ protected: Ptr oldCascade; }; -void CV_EXPORTS_W groupRectangles( vector& rectList, int groupThreshold, double eps, vector* weights, vector* levelWeights ); - + //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// struct CV_EXPORTS_W HOGDescriptor @@ -473,7 +473,7 @@ public: CV_WRAP bool checkDetectorSize() const; CV_WRAP double getWinSigma() const; - CV_WRAP virtual void setSVMDetector(const vector& _svmdetector); + CV_WRAP virtual void setSVMDetector(InputArray _svmdetector); virtual bool read(FileNode& fn); virtual void write(FileStorage& fs, const String& objname) const; diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index b79c92a79c..f2d32002ca 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -83,9 +83,9 @@ bool HOGDescriptor::checkDetectorSize() const detectorSize == descriptorSize + 1; } -void HOGDescriptor::setSVMDetector(const vector& _svmDetector) +void HOGDescriptor::setSVMDetector(InputArray _svmDetector) { - svmDetector = _svmDetector; + _svmDetector.getMat().convertTo(svmDetector, CV_32F); CV_Assert( checkDetectorSize() ); } diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 54f7e38dd8..f99f6524a2 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -762,11 +762,25 @@ static bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name break; std::string k = PyString_AsString(key); if( PyString_Check(item) ) - p.setString(k, PyString_AsString(item)); + { + const char* value = PyString_AsString(item); + p.setString(k, value); + } + else if( PyBool_Check(item) ) + p.setBool(k, item == Py_True); else if( PyInt_Check(item) ) - p.setInt(k, PyInt_AsLong(item)); + { + int value = (int)PyInt_AsLong(item); + if( strcmp(k.c_str(), "algorithm") == 0 ) + p.setAlgorithm(value); + else + p.setInt(k, value); + } else if( PyFloat_Check(item) ) - p.setDouble(k, PyFloat_AsDouble(item)); + { + double value = PyFloat_AsDouble(item); + p.setDouble(k, value); + } else break; } @@ -780,7 +794,7 @@ static bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name static bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name="") { - int d = 0; + int d = (int)dist; bool ok = pyopencv_to(o, d, name); dist = (cvflann::flann_distance_t)d; return ok; diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index a236ac8e5d..2f99236556 100644 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -357,9 +357,9 @@ class FuncVariant(object): continue if a.returnarg: outlist.append((a.name, argno)) - if not a.inputarg or a.returnarg: - if a.isbig(): - outarr_list.append((a.name, argno)) + if (not a.inputarg or a.returnarg) and a.isbig(): + outarr_list.append((a.name, argno)) + if not a.inputarg: continue if not a.defval: arglist.append((a.name, argno))