From 789b35d813848ebddcaf484858c6c7d5532858d7 Mon Sep 17 00:00:00 2001 From: abratchik Date: Sat, 8 Oct 2016 02:13:01 +0400 Subject: [PATCH] improved fix for java wrapper generator (gen_java.py) to avoid generation of java methods with duplicate signatures(v3) --- .../features2d/include/opencv2/features2d.hpp | 24 +++++++------- modules/features2d/src/matchers.cpp | 10 +++--- modules/java/generator/gen_java.py | 32 +++++++++++++------ 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 0fcdc33e48..29f263b4aa 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -918,7 +918,7 @@ public: void radiusMatch( InputArray queryDescriptors, std::vector >& matches, float maxDistance, InputArrayOfArrays masks=noArray(), bool compactResult=false ); - + CV_WRAP void write( const String& fileName ) const { FileStorage fs(fileName, FileStorage::WRITE); @@ -955,9 +955,9 @@ public: - `FlannBased` */ CV_WRAP static Ptr create( const String& descriptorMatcherType ); - + CV_WRAP static Ptr create( int matcherType ); - + protected: /** * Class to work with descriptors from several images as with one merged matrix. @@ -1015,11 +1015,11 @@ class CV_EXPORTS_W BFMatcher : public DescriptorMatcher { public: /** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create() - * - * + * + * */ - CV_WRAP BFMatcher( int _normType=NORM_L2, bool _crossCheck=false ); - + CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false ); + virtual ~BFMatcher() {} virtual bool isMaskSupported() const { return true; } @@ -1035,9 +1035,9 @@ public: matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent pairs. Such technique usually produces best results with minimal number of outliers when there are enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. - */ - CV_WRAP static Ptr create( int _normType=NORM_L2, bool _crossCheck=false ) ; - + */ + CV_WRAP static Ptr create( int normType=NORM_L2, bool crossCheck=false ) ; + virtual Ptr clone( bool emptyTrainData=false ) const; protected: virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, @@ -1060,7 +1060,7 @@ matches of descriptor sets because flann::Index does not support this. : class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher { public: - FlannBasedMatcher( const Ptr& indexParams=makePtr(), + CV_WRAP FlannBasedMatcher( const Ptr& indexParams=makePtr(), const Ptr& searchParams=makePtr() ); virtual void add( InputArrayOfArrays descriptors ); @@ -1075,7 +1075,7 @@ public: virtual bool isMaskSupported() const; CV_WRAP static Ptr create(); - + virtual Ptr clone( bool emptyTrainData=false ) const; protected: static void convertToDMatches( const DescriptorCollection& descriptors, diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 5ec1f675b8..4e9a7b417c 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -696,7 +696,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck ) crossCheck = _crossCheck; } -Ptr BFMatcher::create(int _normType, bool _crossCheck ) +Ptr BFMatcher::create(int _normType, bool _crossCheck ) { return makePtr(_normType, _crossCheck); } @@ -1038,8 +1038,8 @@ Ptr DescriptorMatcher::create( const String& descriptorMatche Ptr DescriptorMatcher::create(int matcherType) { - - + + String name; switch(matcherType) @@ -1068,7 +1068,7 @@ Ptr DescriptorMatcher::create(int matcherType) } return DescriptorMatcher::create(name); - + } @@ -1082,7 +1082,7 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParam CV_Assert( _searchParams ); } -Ptr FlannBasedMatcher::create() +Ptr FlannBasedMatcher::create() { return makePtr(); } diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 6039cdb8e6..7c7303961d 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -1155,6 +1155,7 @@ class JavaWrapperGenerator(object): # java args args = fi.args[:] # copy + j_signatures=[] suffix_counter = int(ci.methods_suffixes.get(fi.jname, -1)) while True: suffix_counter += 1 @@ -1233,6 +1234,25 @@ class JavaWrapperGenerator(object): i += 1 j_epilogue.append( "if("+a.name+"!=null){ " + "; ".join(set_vals) + "; } ") + # calculate java method signature to check for uniqueness + j_args = [] + for a in args: + if not a.ctype: #hidden + continue + jt = type_dict[a.ctype]["j_type"] + if a.out and a.ctype in ('bool', 'int', 'long', 'float', 'double'): + jt += '[]' + j_args.append( jt + ' ' + a.name ) + j_signature = type_dict[fi.ctype]["j_type"] + " " + \ + fi.jname + "(" + ", ".join(j_args) + ")" + logging.info("java: " + j_signature) + + if(j_signature in j_signatures): + if args: + pop(args) + continue + else: + break # java part: # private java NATIVE method decl @@ -1297,15 +1317,6 @@ class JavaWrapperGenerator(object): if fi.classname: static = fi.static - j_args = [] - for a in args: - if not a.ctype: #hidden - continue - jt = type_dict[a.ctype]["j_type"] - if a.out and a.ctype in ('bool', 'int', 'long', 'float', 'double'): - jt += '[]' - j_args.append( jt + ' ' + a.name ) - j_code.write( Template(\ """ public $static $j_type $j_name($j_args) { @@ -1448,6 +1459,9 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname namespace = ('using namespace ' + ci.namespace.replace('.', '::') + ';') if ci.namespace else '' ) ) + # adding method signature to dictionarry + j_signatures.append(j_signature) + # processing args with default values if not args or not args[-1].defval: break