From 084c5958555062a7c2226144cf786c475a744d3a Mon Sep 17 00:00:00 2001 From: abratchik Date: Thu, 13 Oct 2016 13:43:55 +0400 Subject: [PATCH 1/2] fix for legacy FeatureDetector and DescriptorMatcher classes --- .../misc/java/src/cpp/features2d_manual.hpp | 14 ++++++++------ modules/java/generator/gen_java.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/features2d/misc/java/src/cpp/features2d_manual.hpp b/modules/features2d/misc/java/src/cpp/features2d_manual.hpp index d43928d205..6d72bd9de7 100644 --- a/modules/features2d/misc/java/src/cpp/features2d_manual.hpp +++ b/modules/features2d/misc/java/src/cpp/features2d_manual.hpp @@ -89,7 +89,7 @@ public: //supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS BRISK AKAZE Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX) //not supported: SimpleBlob, Dense - CV_WRAP static javaFeatureDetector* create( int detectorType ) + CV_WRAP static Ptr create( int detectorType ) { //String name; if (detectorType > DYNAMICDETECTOR) @@ -156,7 +156,7 @@ public: break; } - return new javaFeatureDetector(fd); + return makePtr(fd); } CV_WRAP void write( const String& fileName ) const @@ -171,10 +171,11 @@ public: wrapped->read(fs.root()); } -private: javaFeatureDetector(Ptr _wrapped) : wrapped(_wrapped) {} +private: + Ptr wrapped; }; @@ -222,7 +223,7 @@ public: //supported SIFT, SURF, ORB, BRIEF, BRISK, FREAK, AKAZE, Opponent(XXXX) //not supported: Calonder - CV_WRAP static javaDescriptorExtractor* create( int extractorType ) + CV_WRAP static Ptr create( int extractorType ) { //String name; @@ -261,7 +262,7 @@ public: break; } - return new javaDescriptorExtractor(de); + return makePtr(de); } CV_WRAP void write( const String& fileName ) const @@ -276,10 +277,11 @@ public: wrapped->read(fs.root()); } -private: javaDescriptorExtractor(Ptr _wrapped) : wrapped(_wrapped) {} +private: + Ptr wrapped; }; diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 2a40ae030a..03afd488d4 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -994,7 +994,7 @@ class JavaWrapperGenerator(object): if classinfo.base: classinfo.addImports(classinfo.base) type_dict["Ptr_"+name] = \ - { "j_type" : name, + { "j_type" : classinfo.jname, "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "jni_name" : "Ptr<"+classinfo.fullName(isCPP=True)+">(("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong", "suffix" : "J" } From 4207ebbce7b13ab968a77ab55af073b176d01679 Mon Sep 17 00:00:00 2001 From: abratchik Date: Fri, 14 Oct 2016 19:21:17 +0400 Subject: [PATCH 2/2] fix for VideoCapture crash --- modules/java/generator/gen_java.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 03afd488d4..c26b443c62 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -783,6 +783,7 @@ class ClassInfo(GeneralInfo): self.imports = set() self.props= [] self.jname = self.name + self.smart = None # True if class stores Ptr* instead of T* in nativeObj field self.j_code = None # java code stream self.jn_code = None # jni code stream self.cpp_code = None # cpp code stream @@ -1392,10 +1393,10 @@ class JavaWrapperGenerator(object): elif fi.static: cvname = fi.fullName(isCPP=True) else: - cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name + cvname = ("me->" if not self.isSmartClass(ci) else "(*me)->") + name c_prologue.append(\ "%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \ - % { "cls" : self.smartWrap(fi.classname, fi.fullClass(isCPP=True))} \ + % { "cls" : self.smartWrap(ci, fi.fullClass(isCPP=True))} \ ) cvargs = [] for a in args: @@ -1541,7 +1542,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete delete (%(cls)s*) self; } -""" % {"module" : module.replace('_', '_1'), "cls" : self.smartWrap(ci.name, ci.fullName(isCPP=True)), "j_cls" : ci.jname.replace('_', '_1')} +""" % {"module" : module.replace('_', '_1'), "cls" : self.smartWrap(ci, ci.fullName(isCPP=True)), "j_cls" : ci.jname.replace('_', '_1')} ) def getClass(self, classname): @@ -1551,17 +1552,31 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete name = classname or self.Module return name in self.classes - def isSmartClass(self, classname): + def isSmartClass(self, ci): ''' Check if class stores Ptr* instead of T* in nativeObj field ''' - return self.isWrapped(classname) + if ci.smart != None: + return ci.smart + + # if parents are smart (we hope) then children are! + # if not we believe the class is smart if it has "create" method + ci.smart = False + if ci.base: + ci.smart = True + else: + for fi in ci.methods: + if fi.name == "create": + ci.smart = True + break + + return ci.smart - def smartWrap(self, name, fullname): + def smartWrap(self, ci, fullname): ''' Wraps fullname with Ptr<> if needed ''' - if self.isSmartClass(name): + if self.isSmartClass(ci): return "Ptr<" + fullname + ">" return fullname