vocabtree  0.0.1
filesystem.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <opencv2/opencv.hpp>
5 
6 /// Provides useful wrappers around many filesystem related functionality, including reading writing
7 /// certain common data structures as well as common operations (ex. file_exists).
8 namespace filesystem {
9  /// Returns the basename of the input filepath, including or not including the extension.
10  std::string basename(const std::string &path, bool include_extension = false);
11  /// Returns true if file exists at location, else returns false.
12  bool file_exists(const std::string& name);
13  /// Recursively creates all directories if needed up to the specified file.
14  void create_file_directory(const std::string &absfilepath);
15  /// Writes a cv::Mat structure to the specified location.
16  bool write_cvmat(const std::string &fname, const cv::Mat &data);
17  /// Loads a cv::Mat structure from the specified location. Returns true if file exists,
18  /// false otherwise.
19  bool load_cvmat(const std::string &fname, cv::Mat &data);
20  /// Writes the BoW feature to the specified location. First dimension of data is cluster index,
21  /// second dimension is TF score.
22  bool write_sparse_vector(const std::string &fname, const std::vector<std::pair<uint32_t, float > > &data);
23  /// Loads the BoW feature from the specified location. First dimension of data is cluster index,
24  /// second dimension is TF score.
25  bool load_sparse_vector(const std::string &fname, std::vector<std::pair<uint32_t, float > > &data);
26  /// Lists all files in the given directory with an optional extension. The extension must include
27  /// the dot (ie. ext=".txt"). If recursive is true (default), will recursively enter all directories
28  std::vector<std::string> list_files(const std::string &path, const std::string &ext = "", bool recursive = true) ;
29  /// Writes a text file to the input file location given the input string. Returns true if success,
30  /// false otherwise.
31  bool write_text(const std::string &fname, const std::string &text);
32 };