From 723b42e0dabae5b79628c654dd17b09be40d83a0 Mon Sep 17 00:00:00 2001 From: Marek Smigielski Date: Fri, 5 Aug 2016 15:34:57 +0200 Subject: [PATCH 1/3] Add namespaces and proper support of the pointers --- modules/java/generator/gen_java.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index f8d3f7d0a5..f5e7aef94b 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -795,7 +795,7 @@ class ClassInfo(GeneralInfo): self.base = re.sub(r"^.*:", "", decl[1].split(",")[0]).strip().replace(self.jname, "") def __repr__(self): - return Template("CLASS $namespace.$classpath.$name : $base").substitute(**self.__dict__) + return Template("CLASS $namespace::$classpath.$name : $base").substitute(**self.__dict__) def getAllImports(self, module): return ["import %s;" % c for c in sorted(self.imports) if not c.startswith('org.opencv.'+module)] @@ -1406,6 +1406,8 @@ class JavaWrapperGenerator(object): clazz = ci.jname cpp_code.write ( Template( \ """ +${namespace} + JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname ($argst); JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname @@ -1440,6 +1442,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname cvargs = ", ".join(cvargs), \ default = default, \ retval = retval, \ + namespace = ('using namespace ' + ci.namespace.replace('.', '::') + ';') if ci.namespace else '' ) ) # processing args with default values @@ -1535,7 +1538,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete ''' Check if class stores Ptr* instead of T* in nativeObj field ''' - return self.isWrapped(classname) and self.classes[classname].base + return False def smartWrap(self, name, fullname): ''' From 1aa14e4929268ae64e897085501dbf7ddf7535e7 Mon Sep 17 00:00:00 2001 From: Marek Smigielski Date: Wed, 10 Aug 2016 12:03:28 +0200 Subject: [PATCH 2/3] fix tab for gen_java.py --- modules/java/generator/gen_java.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index f5e7aef94b..f93870ce05 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -1442,7 +1442,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname cvargs = ", ".join(cvargs), \ default = default, \ retval = retval, \ - namespace = ('using namespace ' + ci.namespace.replace('.', '::') + ';') if ci.namespace else '' + namespace = ('using namespace ' + ci.namespace.replace('.', '::') + ';') if ci.namespace else '' ) ) # processing args with default values @@ -1538,7 +1538,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete ''' Check if class stores Ptr* instead of T* in nativeObj field ''' - return False + return False def smartWrap(self, name, fullname): ''' From 7a7a2749e0b6b3d760076007099e498d0657962c Mon Sep 17 00:00:00 2001 From: mshabunin Date: Fri, 30 Sep 2016 16:21:04 +0300 Subject: [PATCH 3/3] Fixed java wrappers --- modules/java/generator/gen_java.py | 4 ++-- modules/ml/include/opencv2/ml.hpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index f93870ce05..955fbeb9ab 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -1347,7 +1347,7 @@ class JavaWrapperGenerator(object): ret = "return (jlong) new %s(_retval_);" % self.fullTypeName(fi.ctype) elif fi.ctype.startswith('Ptr_'): c_prologue.append("typedef Ptr<%s> %s;" % (self.fullTypeName(fi.ctype[4:]), fi.ctype)) - ret = "%(ctype)s* curval = new %(ctype)s(_retval_);return (jlong)curval->get();" % { 'ctype':fi.ctype } + ret = "return (jlong)(new %(ctype)s(_retval_));" % { 'ctype':fi.ctype } elif self.isWrapped(ret_type): # pointer to wrapped class: ret = "return (jlong) _retval_;" elif type_dict[fi.ctype]["jni_type"] == "jdoubleArray": @@ -1538,7 +1538,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete ''' Check if class stores Ptr* instead of T* in nativeObj field ''' - return False + return self.isWrapped(classname) def smartWrap(self, name, fullname): ''' diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index ea9c89e4e6..ab89c04e6a 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -289,7 +289,7 @@ public: `, containing types of each input and output variable. See ml::VariableTypes. */ - CV_WRAP static Ptr create(InputArray samples, int layout, InputArray responses, + CV_WRAP static Ptr create(InputArray samples, int layout, InputArray responses, InputArray varIdx=noArray(), InputArray sampleIdx=noArray(), InputArray sampleWeights=noArray(), InputArray varType=noArray()); }; @@ -324,7 +324,7 @@ public: @param flags optional flags, depending on the model. Some of the models can be updated with the new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). */ - CV_WRAP virtual bool train( const Ptr& trainData, int flags=0 ); + CV_WRAP virtual bool train( const Ptr& trainData, int flags=0 ); /** @brief Trains the statistical model @@ -347,7 +347,7 @@ public: The method uses StatModel::predict to compute the error. For regression models the error is computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%). */ - CV_WRAP virtual float calcError( const Ptr& data, bool test, OutputArray resp ) const; + CV_WRAP virtual float calcError( const Ptr& data, bool test, OutputArray resp ) const; /** @brief Predicts response(s) for the provided sample(s) @@ -361,7 +361,7 @@ public: The class must implement static `create()` method with no parameters or with all default parameter values */ - template static Ptr<_Tp> train(const Ptr& data, int flags=0) + template static Ptr<_Tp> train(const Ptr& data, int flags=0) { Ptr<_Tp> model = _Tp::create(); return !model.empty() && model->train(data, flags) ? model : Ptr<_Tp>(); @@ -671,7 +671,7 @@ public: regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed. */ - virtual bool trainAuto( const Ptr& data, int kFold = 10, + virtual bool trainAuto( const Ptr& data, int kFold = 10, ParamGrid Cgrid = SVM::getDefaultGrid(SVM::C), ParamGrid gammaGrid = SVM::getDefaultGrid(SVM::GAMMA), ParamGrid pGrid = SVM::getDefaultGrid(SVM::P),