From 88e9a072eccf894172f38903cab2cae6073ea7aa Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 15 Oct 2012 20:46:39 +0400 Subject: [PATCH] Fix binary compatibility of opencv_flann --- modules/flann/include/opencv2/flann/dist.h | 35 +++++++++++++++++++++ modules/flann/include/opencv2/flann/timer.h | 10 +++--- modules/flann/src/miniflann.cpp | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 04fb1ea0a..1800c4f66 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -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 diff --git a/modules/flann/include/opencv2/flann/timer.h b/modules/flann/include/opencv2/flann/timer.h index 6428b0a0d..107371ecd 100644 --- a/modules/flann/include/opencv2/flann/timer.h +++ b/modules/flann/include/opencv2/flann/timer.h @@ -32,7 +32,7 @@ #define OPENCV_FLANN_TIMER_H #include -#include "opencv2/core/core.hpp" + namespace cvflann { @@ -44,7 +44,7 @@ namespace cvflann */ class StartStopTimer { - int64 startTime; + clock_t startTime; public: /** @@ -66,7 +66,7 @@ public: */ void start() { - startTime = cv::getTickCount(); + startTime = clock(); } /** @@ -74,8 +74,8 @@ public: */ void stop() { - int64 stopTime = cv::getTickCount(); - value += ( (double)stopTime - startTime) / cv::getTickFrequency(); + clock_t stopTime = clock(); + value += ( (double)stopTime - startTime) / CLOCKS_PER_SEC; } /** diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp index d8ae2b07c..0a5d47b0c 100644 --- a/modules/flann/src/miniflann.cpp +++ b/modules/flann/src/miniflann.cpp @@ -331,7 +331,7 @@ buildIndex(void*& index, const Mat& data, const IndexParams& params, const Dista #if CV_NEON typedef ::cvflann::Hamming HammingDistance; #else -typedef ::cvflann::HammingLUT HammingDistance; +typedef ::cvflann::HammingLUT2 HammingDistance; #endif Index::Index()