@ -308,7 +308,7 @@ SearchParams::SearchParams( int checks, float eps, bool sorted )
template < typename Distance , typename IndexType > void
buildIndex_ ( void * & index , const Mat & data , const IndexParams & params , const Distance & dist = Distance ( ) )
buildIndex_ ( void * & index , const Mat & wholedata , const Mat & data , const IndexParams & params , const Distance & dist = Distance ( ) )
{
typedef typename Distance : : ElementType ElementType ;
if ( DataType < ElementType > : : type ! = data . type ( ) )
@ -317,15 +317,25 @@ buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Dist
CV_Error ( CV_StsBadArg , " Only continuous arrays are supported " ) ;
: : cvflann : : Matrix < ElementType > dataset ( ( ElementType * ) data . data , data . rows , data . cols ) ;
IndexType * _index = new IndexType ( dataset , get_params ( params ) , dist ) ;
IndexType * _index = NULL ;
if ( ! index | | getParam < flann_algorithm_t > ( params , " algorithm " , FLANN_INDEX_LINEAR ) ! = FLANN_INDEX_LSH ) // currently, additional index support is the lsh algorithm only.
{
_index = new IndexType ( dataset , get_params ( params ) , dist ) ;
_index - > buildIndex ( ) ;
index = _index ;
}
else // build additional lsh index
{
: : cvflann : : Matrix < ElementType > wholedataset ( ( ElementType * ) wholedata . data , wholedata . rows , wholedata . cols ) ;
( ( IndexType * ) index ) - > addIndex ( wholedataset , dataset ) ;
}
}
template < typename Distance > void
buildIndex ( void * & index , const Mat & data , const IndexParams & params , const Distance & dist = Distance ( ) )
buildIndex ( void * & index , const Mat & wholedata , const Mat & data , const IndexParams & params , const Distance & dist = Distance ( ) )
{
buildIndex_ < Distance , : : cvflann : : Index < Distance > > ( index , data , params , dist ) ;
buildIndex_ < Distance , : : cvflann : : Index < Distance > > ( index , wholedata , data , params , dist ) ;
}
# if CV_NEON
@ -348,21 +358,28 @@ Index::Index(InputArray _data, const IndexParams& params, flann_distance_t _dist
featureType = CV_32F ;
algo = FLANN_INDEX_LINEAR ;
distType = FLANN_DIST_L2 ;
build ( _data , params , _distType ) ;
build ( _data , _data , params , _distType ) ;
}
void Index : : build ( InputArray _data , const IndexParams & params , flann_distance_t _distType )
void Index : : build ( InputArray & _wholedata , InputArray & _data , const IndexParams & params , flann_distance_t _distType )
{
release ( ) ;
algo = getParam < flann_algorithm_t > ( params , " algorithm " , FLANN_INDEX_LINEAR ) ;
if ( algo = = FLANN_INDEX_SAVED )
if ( algo ! = FLANN_INDEX_LSH ) // do not release if algo == FLANN_INDEX_LSH
{
release ( ) ;
}
if ( algo = = FLANN_INDEX_SAVED )
{
load ( _data , getParam < std : : string > ( params , " filename " , std : : string ( ) ) ) ;
return ;
}
Mat data = _data . getMat ( ) ;
if ( algo ! = FLANN_INDEX_LSH ) // do not clear if algo == FLANN_INDEX_LSH
{
index = 0 ;
}
featureType = data . type ( ) ;
distType = _distType ;
@ -374,29 +391,29 @@ void Index::build(InputArray _data, const IndexParams& params, flann_distance_t
switch ( distType )
{
case FLANN_DIST_HAMMING :
buildIndex < HammingDistance > ( index , data , params ) ;
buildIndex < HammingDistance > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_L2 :
buildIndex < : : cvflann : : L2 < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : L2 < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_L1 :
buildIndex < : : cvflann : : L1 < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : L1 < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
# if MINIFLANN_SUPPORT_EXOTIC_DISTANCE_TYPES
case FLANN_DIST_MAX :
buildIndex < : : cvflann : : MaxDistance < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : MaxDistance < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_HIST_INTERSECT :
buildIndex < : : cvflann : : HistIntersectionDistance < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : HistIntersectionDistance < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_HELLINGER :
buildIndex < : : cvflann : : HellingerDistance < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : HellingerDistance < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_CHI_SQUARE :
buildIndex < : : cvflann : : ChiSquareDistance < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : ChiSquareDistance < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
case FLANN_DIST_KL :
buildIndex < : : cvflann : : KL_Divergence < float > > ( index , data , params ) ;
buildIndex < : : cvflann : : KL_Divergence < float > > ( index , _wholedata . getMat ( ) , data , params ) ;
break ;
# endif
default :