added BruteForceMatcher (the older variant of BFMatcher) to legacy (ticket #1796). added test for it. Renamed legacy tests to "Legacy_*"
This commit is contained in:
@@ -737,94 +737,6 @@ protected:
|
||||
PixelTestFn test_fn_;
|
||||
};
|
||||
|
||||
/****************************************************************************************\
|
||||
* Distance *
|
||||
\****************************************************************************************/
|
||||
template<typename T>
|
||||
struct CV_EXPORTS Accumulator
|
||||
{
|
||||
typedef T Type;
|
||||
};
|
||||
|
||||
template<> struct Accumulator<unsigned char> { typedef float Type; };
|
||||
template<> struct Accumulator<unsigned short> { typedef float Type; };
|
||||
template<> struct Accumulator<char> { typedef float Type; };
|
||||
template<> struct Accumulator<short> { typedef float Type; };
|
||||
|
||||
/*
|
||||
* Squared Euclidean distance functor
|
||||
*/
|
||||
template<class T>
|
||||
struct CV_EXPORTS SL2
|
||||
{
|
||||
typedef T ValueType;
|
||||
typedef typename Accumulator<T>::Type ResultType;
|
||||
|
||||
ResultType operator()( const T* a, const T* b, int size ) const
|
||||
{
|
||||
return normL2Sqr<ValueType, ResultType>(a, b, size);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Euclidean distance functor
|
||||
*/
|
||||
template<class T>
|
||||
struct CV_EXPORTS L2
|
||||
{
|
||||
typedef T ValueType;
|
||||
typedef typename Accumulator<T>::Type ResultType;
|
||||
|
||||
ResultType operator()( const T* a, const T* b, int size ) const
|
||||
{
|
||||
return (ResultType)sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Manhattan distance (city block distance) functor
|
||||
*/
|
||||
template<class T>
|
||||
struct CV_EXPORTS L1
|
||||
{
|
||||
typedef T ValueType;
|
||||
typedef typename Accumulator<T>::Type ResultType;
|
||||
|
||||
ResultType operator()( const T* a, const T* b, int size ) const
|
||||
{
|
||||
return normL1<ValueType, ResultType>(a, b, size);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
||||
* bit count of A exclusive XOR'ed with B
|
||||
*/
|
||||
struct CV_EXPORTS Hamming
|
||||
{
|
||||
typedef unsigned char ValueType;
|
||||
typedef int ResultType;
|
||||
|
||||
/** this will count the bits in a ^ b
|
||||
*/
|
||||
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
||||
{
|
||||
return normHamming(a, b, size);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Hamming HammingLUT;
|
||||
|
||||
template<int cellsize> struct CV_EXPORTS HammingMultilevel
|
||||
{
|
||||
typedef unsigned char ValueType;
|
||||
typedef int ResultType;
|
||||
|
||||
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const
|
||||
{
|
||||
return normHamming(a, b, size, cellsize);
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************\
|
||||
* DMatch *
|
||||
|
@@ -1,122 +0,0 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#if 0
|
||||
using namespace cv;
|
||||
|
||||
class BruteForceMatcherTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
BruteForceMatcherTest();
|
||||
protected:
|
||||
void run( int );
|
||||
};
|
||||
|
||||
struct CV_EXPORTS L2Fake : public L2<float>
|
||||
{
|
||||
};
|
||||
|
||||
BruteForceMatcherTest::BruteForceMatcherTest() : cvtest::BaseTest( "BruteForceMatcher", "BruteForceMatcher::matchImpl")
|
||||
{
|
||||
support_testing_modes = cvtest::TS::TIMING_MODE;
|
||||
}
|
||||
|
||||
void BruteForceMatcherTest::run( int )
|
||||
{
|
||||
const int dimensions = 64;
|
||||
const int descriptorsNumber = 5000;
|
||||
|
||||
Mat train = Mat( descriptorsNumber, dimensions, CV_32FC1);
|
||||
Mat query = Mat( descriptorsNumber, dimensions, CV_32FC1);
|
||||
|
||||
Mat permutation( 1, descriptorsNumber, CV_32SC1 );
|
||||
for( int i=0;i<descriptorsNumber;i++ )
|
||||
permutation.at<int>( 0, i ) = i;
|
||||
|
||||
//RNG rng = RNG( cvGetTickCount() );
|
||||
RNG rng = RNG( *ts->get_rng() );
|
||||
randShuffle( permutation, 1, &rng );
|
||||
|
||||
float boundary = 500.f;
|
||||
for( int row=0;row<descriptorsNumber;row++ )
|
||||
{
|
||||
for( int col=0;col<dimensions;col++ )
|
||||
{
|
||||
int bit = rng( 2 );
|
||||
train.at<float>( permutation.at<int>( 0, row ), col ) = bit*boundary + rng.uniform( 0.f, boundary );
|
||||
query.at<float>( row, col ) = bit*boundary + rng.uniform( 0.f, boundary );
|
||||
}
|
||||
}
|
||||
|
||||
vector<DMatch> specMatches, genericMatches;
|
||||
BruteForceMatcher<L2<float> > specMatcher;
|
||||
BruteForceMatcher<L2Fake > genericMatcher;
|
||||
|
||||
int64 time0 = cvGetTickCount();
|
||||
specMatcher.match( query, train, specMatches );
|
||||
int64 time1 = cvGetTickCount();
|
||||
genericMatcher.match( query, train, genericMatches );
|
||||
int64 time2 = cvGetTickCount();
|
||||
|
||||
float specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency();
|
||||
ts->printf( cvtest::TS::LOG, "Matching by matrix multiplication time s: %f, us per pair: %f\n",
|
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
float genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency();
|
||||
ts->printf( cvtest::TS::LOG, "Matching without matrix multiplication time s: %f, us per pair: %f\n",
|
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
if( (int)specMatches.size() != descriptorsNumber || (int)genericMatches.size() != descriptorsNumber )
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
for( int i=0;i<descriptorsNumber;i++ )
|
||||
{
|
||||
float epsilon = 0.01f;
|
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon &&
|
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx &&
|
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx;
|
||||
if( !isEquiv || specMatches[i].trainIdx != permutation.at<int>( 0, i ) )
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Test mask
|
||||
Mat mask( query.rows, train.rows, CV_8UC1 );
|
||||
rng.fill( mask, RNG::UNIFORM, 0, 2 );
|
||||
|
||||
|
||||
time0 = cvGetTickCount();
|
||||
specMatcher.match( query, train, specMatches, mask );
|
||||
time1 = cvGetTickCount();
|
||||
genericMatcher.match( query, train, genericMatches, mask );
|
||||
time2 = cvGetTickCount();
|
||||
|
||||
specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency();
|
||||
ts->printf( cvtest::TS::LOG, "Matching by matrix multiplication time with mask s: %f, us per pair: %f\n",
|
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency();
|
||||
ts->printf( cvtest::TS::LOG, "Matching without matrix multiplication time with mask s: %f, us per pair: %f\n",
|
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
if( specMatches.size() != genericMatches.size() )
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
|
||||
for( size_t i=0;i<specMatches.size();i++ )
|
||||
{
|
||||
//float epsilon = 1e-2;
|
||||
float epsilon = 10000000;
|
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon &&
|
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx &&
|
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx;
|
||||
if( !isEquiv )
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BruteForceMatcherTest taBruteForceMatcherTest;
|
||||
#endif
|
Reference in New Issue
Block a user