PICCANTE  0.4
The hottest HDR imaging library!
binary_feature_lsh_matcher.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FEATURES_MATCHING_BINARY_FEATURE_LSH_MATCHER_HPP
19 #define PIC_FEATURES_MATCHING_BINARY_FEATURE_LSH_MATCHER_HPP
20 
21 #include <vector>
22 
23 #include "../base.hpp"
24 #include "../features_matching/hash_table_lsh.hpp"
25 #include "../features_matching/feature_matcher.hpp"
26 
27 namespace pic {
28 
29 #ifndef PIC_DISABLE_EIGEN
30 
35 {
36 protected:
37  std::vector< HashTableLSH* > tables;
39 
40 public:
41 
45  BinaryFeatureLSHMatcher(std::vector< uint *> *descs, uint desc_size, uint nTables = 32, uint hash_size = 8) : FeatureMatcher<uint>(descs, desc_size)
46  {
47  this->R = ((desc_size * sizeof(uint) * 8) * 90) / 100;
48 
49  std::mt19937 m_rnd(1);
50 
51  for(uint i=0; i < nTables; i++) {
52  uint n = desc_size * sizeof(uint) * 8;
53  uint *g_f = getHash(m_rnd, n, hash_size);
54  HashTableLSH *tmp = new HashTableLSH(hash_size, g_f, descs, desc_size);
55  tables.push_back(tmp);
56  }
57  }
58 
66  static uint *getHash(std::mt19937 &m, uint dim, uint hash_size = 0)
67  {
68  if(hash_size == 0) {
69  hash_size = 8;
70  }
71 
72  uint *out = new uint[hash_size];
73 
74  std::set<uint> tmp;
75 
76  int c = 0;
77  while (tmp.size() < hash_size) {
78  uint val = m() % dim;
79  auto result = tmp.insert(val);
80 
81  if(result.second) {
82  out[c] = val;
83  c++;
84  }
85  }
86 
87  return out;
88  }
89 
97  bool getMatch(uint *desc, int &matched_j, uint &dist_1)
98  {
99  uint dist_2 = 0;
100 
101  dist_1 = R;
102  matched_j = -1;
103 
104  for(uint i = 0; i < tables.size(); i++) {
105  tables[i]->getNearest(desc, matched_j, dist_1, dist_2);
106  }
107 
108  return (matched_j != -1);// && (dist_1 * 100 > dist_2 * 105);
109  }
110 };
111 
112 #endif
113 
114 } // end namespace pic
115 
116 #endif /* PIC_FEATURES_MATCHING_BINARY_FEATURE_LSH_MATCHER_HPP */
117 
unsigned int uint
Definition: base.hpp:23
The Hash class.
Definition: hash_table_lsh.hpp:34
static uint * getHash(std::mt19937 &m, uint dim, uint hash_size=0)
getHash
Definition: binary_feature_lsh_matcher.hpp:66
The FeatureMatcher class.
Definition: feature_matcher.hpp:39
uint R
Definition: binary_feature_lsh_matcher.hpp:38
The LSH class.
Definition: binary_feature_lsh_matcher.hpp:34
std::vector< uint *> * descs
Definition: feature_matcher.hpp:42
std::vector< HashTableLSH *> tables
Definition: binary_feature_lsh_matcher.hpp:37
Definition: bilateral_separation.hpp:25
BinaryFeatureLSHMatcher(std::vector< uint *> *descs, uint desc_size, uint nTables=32, uint hash_size=8)
LSH.
Definition: binary_feature_lsh_matcher.hpp:45
bool getMatch(uint *desc, int &matched_j, uint &dist_1)
getMatch
Definition: binary_feature_lsh_matcher.hpp:97
uint desc_size
Definition: feature_matcher.hpp:43