之前项目中用到LSH算法来做特征检索,对LSH算法很好奇,最近看了LSH的论文,依照自己的理解,初步写了LSH代码。测试效果不是特别理想,参数的选择也基本靠尝试,姑且先把代码放上来,之后再改进吧(2016.01.24)
代码块
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
const int k = 700;
const int l = 10;
const int MaxValue = 255;
const int M = 100;
struct Bucket
{
vector<Mat> features;
vector<int> names;
int bucketSize;
};
struct Table
{
vector<Bucket> bucket;
int TableSize;
};
class myLSH
{
public:
myLSH(){};
~myLSH(){};
public:
int Init( int m, int l, float ratio,int featureDims );
int train(Mat featurtes);
int Search(Mat feature,int& name, int& dist);
private:
int GetHashFun_level1();
int Hash_level1( Mat feature,int hashFunID,vector<unsigned char>& value );
int Hash_level2( vector<unsigned