improved fix for java wrapper generator (gen_java.py) to avoid generation of java methods with duplicate signatures(v3)

pull/7432/head
abratchik 8 years ago
parent be028d0774
commit 789b35d813
  1. 24
      modules/features2d/include/opencv2/features2d.hpp
  2. 10
      modules/features2d/src/matchers.cpp
  3. 32
      modules/java/generator/gen_java.py

@ -918,7 +918,7 @@ public:
void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& 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<DescriptorMatcher> create( const String& descriptorMatcherType );
CV_WRAP static Ptr<DescriptorMatcher> 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<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;
protected:
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. :
class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
{
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>() );
virtual void add( InputArrayOfArrays descriptors );
@ -1075,7 +1075,7 @@ public:
virtual bool isMaskSupported() const;
CV_WRAP static Ptr<FlannBasedMatcher> create();
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
protected:
static void convertToDMatches( const DescriptorCollection& descriptors,

@ -696,7 +696,7 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck )
crossCheck = _crossCheck;
}
Ptr<BFMatcher> BFMatcher::create(int _normType, bool _crossCheck )
Ptr<BFMatcher> BFMatcher::create(int _normType, bool _crossCheck )
{
return makePtr<BFMatcher>(_normType, _crossCheck);
}
@ -1038,8 +1038,8 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatche
Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType)
{
String name;
switch(matcherType)
@ -1068,7 +1068,7 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType)
}
return DescriptorMatcher::create(name);
}
@ -1082,7 +1082,7 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParam
CV_Assert( _searchParams );
}
Ptr<FlannBasedMatcher> FlannBasedMatcher::create()
Ptr<FlannBasedMatcher> FlannBasedMatcher::create()
{
return makePtr<FlannBasedMatcher>();
}

@ -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

Loading…
Cancel
Save