Commit 789b35d8 authored by abratchik's avatar abratchik

improved fix for java wrapper generator (gen_java.py) to avoid generation of…

improved fix for java wrapper generator (gen_java.py) to avoid generation of java methods with duplicate signatures(v3)
parent be028d07
...@@ -918,7 +918,7 @@ public: ...@@ -918,7 +918,7 @@ public:
void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
InputArrayOfArrays masks=noArray(), bool compactResult=false ); InputArrayOfArrays masks=noArray(), bool compactResult=false );
CV_WRAP void write( const String& fileName ) const CV_WRAP void write( const String& fileName ) const
{ {
FileStorage fs(fileName, FileStorage::WRITE); FileStorage fs(fileName, FileStorage::WRITE);
...@@ -955,9 +955,9 @@ public: ...@@ -955,9 +955,9 @@ public:
- `FlannBased` - `FlannBased`
*/ */
CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType ); CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType );
CV_WRAP static Ptr<DescriptorMatcher> create( int matcherType ); CV_WRAP static Ptr<DescriptorMatcher> create( int matcherType );
protected: protected:
/** /**
* Class to work with descriptors from several images as with one merged matrix. * Class to work with descriptors from several images as with one merged matrix.
...@@ -1015,11 +1015,11 @@ class CV_EXPORTS_W BFMatcher : public DescriptorMatcher ...@@ -1015,11 +1015,11 @@ class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
{ {
public: public:
/** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create() /** @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 ~BFMatcher() {}
virtual bool isMaskSupported() const { return true; } virtual bool isMaskSupported() const { return true; }
...@@ -1035,9 +1035,9 @@ public: ...@@ -1035,9 +1035,9 @@ public:
matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent 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 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. enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
*/ */
CV_WRAP static Ptr<BFMatcher> create( int _normType=NORM_L2, bool _crossCheck=false ) ; CV_WRAP static Ptr<BFMatcher> create( int normType=NORM_L2, bool crossCheck=false ) ;
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const; virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
protected: protected:
virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
...@@ -1060,7 +1060,7 @@ matches of descriptor sets because flann::Index does not support this. : ...@@ -1060,7 +1060,7 @@ matches of descriptor sets because flann::Index does not support this. :
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
{ {
public: public:
FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(), CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() ); const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
virtual void add( InputArrayOfArrays descriptors ); virtual void add( InputArrayOfArrays descriptors );
...@@ -1075,7 +1075,7 @@ public: ...@@ -1075,7 +1075,7 @@ public:
virtual bool isMaskSupported() const; virtual bool isMaskSupported() const;
CV_WRAP static Ptr<FlannBasedMatcher> create(); CV_WRAP static Ptr<FlannBasedMatcher> create();
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const; virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
protected: protected:
static void convertToDMatches( const DescriptorCollection& descriptors, static void convertToDMatches( const DescriptorCollection& descriptors,
......
...@@ -696,7 +696,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck ) ...@@ -696,7 +696,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck )
crossCheck = _crossCheck; crossCheck = _crossCheck;
} }
Ptr<BFMatcher> BFMatcher::create(int _normType, bool _crossCheck ) Ptr<BFMatcher> BFMatcher::create(int _normType, bool _crossCheck )
{ {
return makePtr<BFMatcher>(_normType, _crossCheck); return makePtr<BFMatcher>(_normType, _crossCheck);
} }
...@@ -1038,8 +1038,8 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatche ...@@ -1038,8 +1038,8 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatche
Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType) Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType)
{ {
String name; String name;
switch(matcherType) switch(matcherType)
...@@ -1068,7 +1068,7 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType) ...@@ -1068,7 +1068,7 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType)
} }
return DescriptorMatcher::create(name); return DescriptorMatcher::create(name);
} }
...@@ -1082,7 +1082,7 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParam ...@@ -1082,7 +1082,7 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParam
CV_Assert( _searchParams ); CV_Assert( _searchParams );
} }
Ptr<FlannBasedMatcher> FlannBasedMatcher::create() Ptr<FlannBasedMatcher> FlannBasedMatcher::create()
{ {
return makePtr<FlannBasedMatcher>(); return makePtr<FlannBasedMatcher>();
} }
......
...@@ -1155,6 +1155,7 @@ class JavaWrapperGenerator(object): ...@@ -1155,6 +1155,7 @@ class JavaWrapperGenerator(object):
# java args # java args
args = fi.args[:] # copy args = fi.args[:] # copy
j_signatures=[]
suffix_counter = int(ci.methods_suffixes.get(fi.jname, -1)) suffix_counter = int(ci.methods_suffixes.get(fi.jname, -1))
while True: while True:
suffix_counter += 1 suffix_counter += 1
...@@ -1233,6 +1234,25 @@ class JavaWrapperGenerator(object): ...@@ -1233,6 +1234,25 @@ class JavaWrapperGenerator(object):
i += 1 i += 1
j_epilogue.append( "if("+a.name+"!=null){ " + "; ".join(set_vals) + "; } ") 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: # java part:
# private java NATIVE method decl # private java NATIVE method decl
...@@ -1297,15 +1317,6 @@ class JavaWrapperGenerator(object): ...@@ -1297,15 +1317,6 @@ class JavaWrapperGenerator(object):
if fi.classname: if fi.classname:
static = fi.static 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(\ j_code.write( Template(\
""" public $static $j_type $j_name($j_args) """ public $static $j_type $j_name($j_args)
{ {
...@@ -1448,6 +1459,9 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname ...@@ -1448,6 +1459,9 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname
namespace = ('using namespace ' + ci.namespace.replace('.', '::') + ';') if ci.namespace else '' 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 # processing args with default values
if not args or not args[-1].defval: if not args or not args[-1].defval:
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment