vocabtree  0.0.1
search_base.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utils/image.hpp>
4 #include <utils/dataset.hpp>
5 
6 #include <cstdint>
7 #include <vector>
8 #include <string>
9 #include <memory>
10 
11 /// Structure to hold input training parameters (ex. #clusters, #examples to consider)
13 };
14 
15 /// Structure to hold input search parameters (ex. #matches, threshold, number neighbors to consider, etc.)
17 };
18 
19 
20 /// Structure to hold returned match results (returned from a search call).
22  std::vector<uint64_t> matches;
23 
24 };
25 
26 
27 /// Abstract class from which all search structures and methods derive from. Each search method
28 /// must implement train, search, load and save.
29 class SearchBase {
30 
31 public:
32  SearchBase();
33  SearchBase(const std::string &file_path);
34 
35  virtual ~SearchBase();
36 
37  /// Given a set of training parameters, list of images, trains. Returns true if successful, false
38  /// if not successful.
39  virtual bool train (Dataset &dataset, const std::shared_ptr<const TrainParamsBase> &params, const std::vector< std::shared_ptr<const Image > > &examples) = 0;
40 
41  /// Given a set of search parameters, list of query images, searches for matching images and returns the result
42  /// matches.
43  std::vector< std::shared_ptr<MatchResultsBase> > search(Dataset &dataset, const std::shared_ptr<SearchParamsBase> &params,
44  const std::vector< std::shared_ptr<const Image > > &examples);
45 
46  /// Loads a trained search structure from the input filepath
47  virtual bool load (const std::string &file_path) = 0;
48 
49  /// Saves a trained search structure to the input filepath
50  virtual bool save (const std::string &file_path) const = 0;
51 
52 protected:
53 
54  /// Given a set of search parameters, a query images, searches for matching images and returns the match
55  virtual std::shared_ptr<MatchResultsBase> search(Dataset &dataset, const std::shared_ptr<const SearchParamsBase> &params, const std::shared_ptr<const Image > &example) = 0;
56 
57 private:
58 
59 };