mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 19:24:07 +08:00
Merge pull request #7432 from abratchik:java.wrapper.fix.3.1
This commit is contained in:
commit
4ed40fd694
@ -771,6 +771,15 @@ an image set.
|
|||||||
class CV_EXPORTS_W DescriptorMatcher : public Algorithm
|
class CV_EXPORTS_W DescriptorMatcher : public Algorithm
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
FLANNBASED = 1,
|
||||||
|
BRUTEFORCE = 2,
|
||||||
|
BRUTEFORCE_L1 = 3,
|
||||||
|
BRUTEFORCE_HAMMING = 4,
|
||||||
|
BRUTEFORCE_HAMMINGLUT = 5,
|
||||||
|
BRUTEFORCE_SL2 = 6
|
||||||
|
};
|
||||||
virtual ~DescriptorMatcher();
|
virtual ~DescriptorMatcher();
|
||||||
|
|
||||||
/** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor
|
/** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor
|
||||||
@ -868,7 +877,7 @@ public:
|
|||||||
query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are
|
query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are
|
||||||
returned in the distance increasing order.
|
returned in the distance increasing order.
|
||||||
*/
|
*/
|
||||||
void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
CV_WRAP void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
|
||||||
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
||||||
InputArray mask=noArray(), bool compactResult=false ) const;
|
InputArray mask=noArray(), bool compactResult=false ) const;
|
||||||
|
|
||||||
@ -909,6 +918,18 @@ 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
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::WRITE);
|
||||||
|
write(fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP void read( const String& fileName )
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::READ);
|
||||||
|
read(fs.root());
|
||||||
|
}
|
||||||
// Reads matcher object from a file node
|
// Reads matcher object from a file node
|
||||||
virtual void read( const FileNode& );
|
virtual void read( const FileNode& );
|
||||||
// Writes matcher object to a file storage
|
// Writes matcher object to a file storage
|
||||||
@ -920,7 +941,7 @@ public:
|
|||||||
that is, copies both parameters and train data. If emptyTrainData is true, the method creates an
|
that is, copies both parameters and train data. If emptyTrainData is true, the method creates an
|
||||||
object copy with the current parameters but with empty train data.
|
object copy with the current parameters but with empty train data.
|
||||||
*/
|
*/
|
||||||
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
|
CV_WRAP virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
|
||||||
|
|
||||||
/** @brief Creates a descriptor matcher of a given type with the default parameters (using default
|
/** @brief Creates a descriptor matcher of a given type with the default parameters (using default
|
||||||
constructor).
|
constructor).
|
||||||
@ -934,6 +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 );
|
||||||
|
|
||||||
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.
|
||||||
@ -990,8 +1014,17 @@ sets.
|
|||||||
class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
|
class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** @brief Brute-force matcher constructor.
|
/** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create()
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false );
|
||||||
|
|
||||||
|
virtual ~BFMatcher() {}
|
||||||
|
|
||||||
|
virtual bool isMaskSupported() const { return true; }
|
||||||
|
|
||||||
|
/* @brief Brute-force matcher create method.
|
||||||
@param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are
|
@param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are
|
||||||
preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
|
preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
|
||||||
BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
|
BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
|
||||||
@ -1003,10 +1036,7 @@ public:
|
|||||||
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 BFMatcher( int normType=NORM_L2, bool crossCheck=false );
|
CV_WRAP static Ptr<BFMatcher> create( int normType=NORM_L2, bool crossCheck=false ) ;
|
||||||
virtual ~BFMatcher() {}
|
|
||||||
|
|
||||||
virtual bool isMaskSupported() const { return true; }
|
|
||||||
|
|
||||||
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
|
||||||
protected:
|
protected:
|
||||||
@ -1044,6 +1074,8 @@ public:
|
|||||||
virtual void train();
|
virtual void train();
|
||||||
virtual bool isMaskSupported() const;
|
virtual bool isMaskSupported() const;
|
||||||
|
|
||||||
|
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,
|
||||||
|
@ -178,120 +178,6 @@ private:
|
|||||||
Ptr<FeatureDetector> wrapped;
|
Ptr<FeatureDetector> wrapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CV_WRAP bool isMaskSupported() const
|
|
||||||
{ return wrapped->isMaskSupported(); }
|
|
||||||
|
|
||||||
CV_WRAP void add( const std::vector<Mat>& descriptors )
|
|
||||||
{ return wrapped->add(descriptors); }
|
|
||||||
|
|
||||||
CV_WRAP const std::vector<Mat>& getTrainDescriptors() const
|
|
||||||
{ return wrapped->getTrainDescriptors(); }
|
|
||||||
|
|
||||||
CV_WRAP void clear()
|
|
||||||
{ return wrapped->clear(); }
|
|
||||||
|
|
||||||
CV_WRAP bool empty() const
|
|
||||||
{ return wrapped->empty(); }
|
|
||||||
|
|
||||||
CV_WRAP void train()
|
|
||||||
{ return wrapped->train(); }
|
|
||||||
|
|
||||||
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
|
||||||
CV_OUT std::vector<DMatch>& matches, const Mat& mask=Mat() ) const
|
|
||||||
{ return wrapped->match(queryDescriptors, trainDescriptors, matches, mask); }
|
|
||||||
|
|
||||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
|
||||||
CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
|
||||||
const Mat& mask=Mat(), bool compactResult=false ) const
|
|
||||||
{ return wrapped->knnMatch(queryDescriptors, trainDescriptors, matches, k, mask, compactResult); }
|
|
||||||
|
|
||||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
|
||||||
CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
||||||
const Mat& mask=Mat(), bool compactResult=false ) const
|
|
||||||
{ return wrapped->radiusMatch(queryDescriptors, trainDescriptors, matches, maxDistance, mask, compactResult); }
|
|
||||||
|
|
||||||
CV_WRAP void match( const Mat& queryDescriptors, CV_OUT std::vector<DMatch>& matches,
|
|
||||||
const std::vector<Mat>& masks=std::vector<Mat>() )
|
|
||||||
{ return wrapped->match(queryDescriptors, matches, masks); }
|
|
||||||
|
|
||||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
|
|
||||||
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false )
|
|
||||||
{ return wrapped->knnMatch(queryDescriptors, matches, k, masks, compactResult); }
|
|
||||||
|
|
||||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
|
||||||
const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false )
|
|
||||||
{ return wrapped->radiusMatch(queryDescriptors, matches, maxDistance, masks, compactResult); }
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
FLANNBASED = 1,
|
|
||||||
BRUTEFORCE = 2,
|
|
||||||
BRUTEFORCE_L1 = 3,
|
|
||||||
BRUTEFORCE_HAMMING = 4,
|
|
||||||
BRUTEFORCE_HAMMINGLUT = 5,
|
|
||||||
BRUTEFORCE_SL2 = 6
|
|
||||||
};
|
|
||||||
|
|
||||||
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
|
||||||
{
|
|
||||||
return new javaDescriptorMatcher(wrapped->clone(emptyTrainData));
|
|
||||||
}
|
|
||||||
|
|
||||||
//supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
|
|
||||||
CV_WRAP static javaDescriptorMatcher* create( int matcherType )
|
|
||||||
{
|
|
||||||
String name;
|
|
||||||
|
|
||||||
switch(matcherType)
|
|
||||||
{
|
|
||||||
case FLANNBASED:
|
|
||||||
name = "FlannBased";
|
|
||||||
break;
|
|
||||||
case BRUTEFORCE:
|
|
||||||
name = "BruteForce";
|
|
||||||
break;
|
|
||||||
case BRUTEFORCE_L1:
|
|
||||||
name = "BruteForce-L1";
|
|
||||||
break;
|
|
||||||
case BRUTEFORCE_HAMMING:
|
|
||||||
name = "BruteForce-Hamming";
|
|
||||||
break;
|
|
||||||
case BRUTEFORCE_HAMMINGLUT:
|
|
||||||
name = "BruteForce-HammingLUT";
|
|
||||||
break;
|
|
||||||
case BRUTEFORCE_SL2:
|
|
||||||
name = "BruteForce-SL2";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
CV_Error( Error::StsBadArg, "Specified descriptor matcher type is not supported." );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new javaDescriptorMatcher(DescriptorMatcher::create(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
CV_WRAP void write( const String& fileName ) const
|
|
||||||
{
|
|
||||||
FileStorage fs(fileName, FileStorage::WRITE);
|
|
||||||
wrapped->write(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
CV_WRAP void read( const String& fileName )
|
|
||||||
{
|
|
||||||
FileStorage fs(fileName, FileStorage::READ);
|
|
||||||
wrapped->read(fs.root());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
javaDescriptorMatcher(Ptr<DescriptorMatcher> _wrapped) : wrapped(_wrapped)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Ptr<DescriptorMatcher> wrapped;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor
|
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -696,6 +696,11 @@ BFMatcher::BFMatcher( int _normType, bool _crossCheck )
|
|||||||
crossCheck = _crossCheck;
|
crossCheck = _crossCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr<BFMatcher> BFMatcher::create(int _normType, bool _crossCheck )
|
||||||
|
{
|
||||||
|
return makePtr<BFMatcher>(_normType, _crossCheck);
|
||||||
|
}
|
||||||
|
|
||||||
Ptr<DescriptorMatcher> BFMatcher::clone( bool emptyTrainData ) const
|
Ptr<DescriptorMatcher> BFMatcher::clone( bool emptyTrainData ) const
|
||||||
{
|
{
|
||||||
Ptr<BFMatcher> matcher = makePtr<BFMatcher>(normType, crossCheck);
|
Ptr<BFMatcher> matcher = makePtr<BFMatcher>(normType, crossCheck);
|
||||||
@ -1031,6 +1036,41 @@ Ptr<DescriptorMatcher> DescriptorMatcher::create( const String& descriptorMatche
|
|||||||
return dm;
|
return dm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr<DescriptorMatcher> DescriptorMatcher::create(int matcherType)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
String name;
|
||||||
|
|
||||||
|
switch(matcherType)
|
||||||
|
{
|
||||||
|
case FLANNBASED:
|
||||||
|
name = "FlannBased";
|
||||||
|
break;
|
||||||
|
case BRUTEFORCE:
|
||||||
|
name = "BruteForce";
|
||||||
|
break;
|
||||||
|
case BRUTEFORCE_L1:
|
||||||
|
name = "BruteForce-L1";
|
||||||
|
break;
|
||||||
|
case BRUTEFORCE_HAMMING:
|
||||||
|
name = "BruteForce-Hamming";
|
||||||
|
break;
|
||||||
|
case BRUTEFORCE_HAMMINGLUT:
|
||||||
|
name = "BruteForce-HammingLUT";
|
||||||
|
break;
|
||||||
|
case BRUTEFORCE_SL2:
|
||||||
|
name = "BruteForce-SL2";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CV_Error( Error::StsBadArg, "Specified descriptor matcher type is not supported." );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DescriptorMatcher::create(name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flann based matcher
|
* Flann based matcher
|
||||||
@ -1042,6 +1082,11 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParam
|
|||||||
CV_Assert( _searchParams );
|
CV_Assert( _searchParams );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr<FlannBasedMatcher> FlannBasedMatcher::create()
|
||||||
|
{
|
||||||
|
return makePtr<FlannBasedMatcher>();
|
||||||
|
}
|
||||||
|
|
||||||
void FlannBasedMatcher::add( InputArrayOfArrays _descriptors )
|
void FlannBasedMatcher::add( InputArrayOfArrays _descriptors )
|
||||||
{
|
{
|
||||||
DescriptorMatcher::add( _descriptors );
|
DescriptorMatcher::add( _descriptors );
|
||||||
|
@ -14,7 +14,7 @@ class_ignore_list = (
|
|||||||
#core
|
#core
|
||||||
"FileNode", "FileStorage", "KDTree", "KeyPoint", "DMatch",
|
"FileNode", "FileStorage", "KDTree", "KeyPoint", "DMatch",
|
||||||
#features2d
|
#features2d
|
||||||
"SimpleBlobDetector", "FlannBasedMatcher", "DescriptorMatcher"
|
"SimpleBlobDetector"
|
||||||
)
|
)
|
||||||
|
|
||||||
const_ignore_list = (
|
const_ignore_list = (
|
||||||
@ -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):
|
|||||||
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):
|
|||||||
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
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user