diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index fad73a2715..a1b557fa9e 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -517,30 +517,32 @@ DescriptorMatcher::~DescriptorMatcher() void DescriptorMatcher::add( InputArrayOfArrays _descriptors ) { - if(_descriptors.isUMatVector()) + if( _descriptors.isUMatVector() ) { std::vector descriptors; - _descriptors.getUMatVector(descriptors); + _descriptors.getUMatVector( descriptors ); utrainDescCollection.insert( utrainDescCollection.end(), descriptors.begin(), descriptors.end() ); } - else if(_descriptors.isUMat()) + else if( _descriptors.isUMat() ) { std::vector descriptors = std::vector(1, _descriptors.getUMat()); utrainDescCollection.insert( utrainDescCollection.end(), descriptors.begin(), descriptors.end() ); } - else if(_descriptors.isMatVector()) + else if( _descriptors.isMatVector() ) { std::vector descriptors; _descriptors.getMatVector(descriptors); trainDescCollection.insert( trainDescCollection.end(), descriptors.begin(), descriptors.end() ); } - else if(_descriptors.isMat()) + else if( _descriptors.isMat() ) { std::vector descriptors = std::vector(1, _descriptors.getMat()); trainDescCollection.insert( trainDescCollection.end(), descriptors.begin(), descriptors.end() ); } else + { CV_Assert( _descriptors.isUMat() || _descriptors.isUMatVector() || _descriptors.isMat() || _descriptors.isMatVector() ); + } } const std::vector& DescriptorMatcher::getTrainDescriptors() const @@ -1032,12 +1034,37 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParam void FlannBasedMatcher::add( InputArrayOfArrays _descriptors ) { DescriptorMatcher::add( _descriptors ); - std::vector descriptors; - _descriptors.getUMatVector(descriptors); - for( size_t i = 0; i < descriptors.size(); i++ ) + if( _descriptors.isUMatVector() ) { - addedDescCount += descriptors[i].rows; + std::vector descriptors; + _descriptors.getUMatVector( descriptors ); + + for( size_t i = 0; i < descriptors.size(); i++ ) + { + addedDescCount += descriptors[i].rows; + } + } + else if( _descriptors.isUMat() ) + { + addedDescCount += _descriptors.getUMat().rows; + } + else if( _descriptors.isMatVector() ) + { + std::vector descriptors; + _descriptors.getMatVector(descriptors); + for( size_t i = 0; i < descriptors.size(); i++ ) + { + addedDescCount += descriptors[i].rows; + } + } + else if( _descriptors.isMat() ) + { + addedDescCount += _descriptors.getMat().rows; + } + else + { + CV_Assert( _descriptors.isUMat() || _descriptors.isUMatVector() || _descriptors.isMat() || _descriptors.isMatVector() ); } }