Fix parsing of training vecs for FlannBasedMatcher

FlannBasedMatcher::add is overloaded, but the style of parsing the
InputArrayOfArrays does not match the style from
DescriptorMatcher::add. The issue is that InputArrayOfArrays
must be properly marshalled so that the data can be read
correctly. In this case, the method expects the training
descriptors to be either a vector of matrices or a single matrix
(as is shown in DescriptorMatcher::add). These code
replicates that for the case of the FlannBasedMatcher::add.

In fact, a similar commit to this was added by 26d9a7c but was
ultimately not accepted in #4111. This is likely due to the
fact that the input arrays were not parsed properly and the
case of a single matrix was being improperly handled. I believe
this commit to be correct given the logic from
DescriptorMatcher::add.
This commit is contained in:
Patrick Snape 2016-01-23 15:58:16 +00:00
parent 2f5ea3437e
commit 05cfe28612

View File

@ -1034,12 +1034,37 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr<flann::IndexParams>& _indexParam
void FlannBasedMatcher::add( InputArrayOfArrays _descriptors ) void FlannBasedMatcher::add( InputArrayOfArrays _descriptors )
{ {
DescriptorMatcher::add( _descriptors ); DescriptorMatcher::add( _descriptors );
std::vector<UMat> descriptors;
_descriptors.getUMatVector(descriptors);
for( size_t i = 0; i < descriptors.size(); i++ ) if( _descriptors.isUMatVector() )
{ {
addedDescCount += descriptors[i].rows; std::vector<UMat> 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<Mat> 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() );
} }
} }