|
|
|
@ -380,6 +380,41 @@ struct HammingLUT |
|
|
|
|
typedef unsigned char ElementType; |
|
|
|
|
typedef int ResultType; |
|
|
|
|
|
|
|
|
|
/** this will count the bits in a ^ b
|
|
|
|
|
*/ |
|
|
|
|
ResultType operator()(const unsigned char* a, const unsigned char* b, int size) const |
|
|
|
|
{ |
|
|
|
|
static const uchar popCountTable[] =
|
|
|
|
|
{ |
|
|
|
|
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
|
|
|
|
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
|
|
|
|
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
|
|
|
|
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
|
|
|
|
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
|
|
|
|
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
|
|
|
|
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
|
|
|
|
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 |
|
|
|
|
}; |
|
|
|
|
ResultType result = 0; |
|
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
|
result += popCountTable[a[i] ^ b[i]]; |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 HammingLUT2 |
|
|
|
|
{ |
|
|
|
|
typedef False is_kdtree_distance; |
|
|
|
|
typedef False is_vector_space_distance; |
|
|
|
|
|
|
|
|
|
typedef unsigned char ElementType; |
|
|
|
|
typedef int ResultType; |
|
|
|
|
|
|
|
|
|
/** this will count the bits in a ^ b
|
|
|
|
|
*/ |
|
|
|
|
ResultType operator()(const unsigned char* a, const unsigned char* b, size_t size) const |
|
|
|
|