Superpixel Benchmark
Superpixel benchmark, tools and algorithms.
io_util.h
Go to the documentation of this file.
1 
32 #ifndef IO_UTIL_H
33 #define IO_UTIL_H
34 
35 #include <vector>
36 #include <map>
37 #include <string>
38 #include <boost/filesystem.hpp>
39 #include <opencv2/opencv.hpp>
40 
41 #ifndef DIRECTORY_SEPARATOR
42  #if defined(WIN32) || defined(_WIN32)
43  #define DIRECTORY_SEPARATOR "\\"
44  #else
45  #define DIRECTORY_SEPARATOR "/"
46  #endif
47 #endif
48 
52 class IOUtil {
53 public:
60  static int readMat(boost::filesystem::path file, cv::Mat &mat, std::string field = "mat");
61 
71  static int writeMat(boost::filesystem::path file, const cv::Mat& mat,
72  std::string field = "mat");
73 
83  template<typename T>
84  static int writeArrayCSV(boost::filesystem::path file, T** array, int rows, int cols,
85  std::string separator = ",", int precision = 6);
86 
97  template<typename T>
98  static int writeMatCSV(boost::filesystem::path file, const cv::Mat& mat,
99  std::string separator = ",", int precision = 6);
100 
106  static int readMatCSVInt(boost::filesystem::path file, cv::Mat &result);
107 
115  static int readMatCSVInt(boost::filesystem::path file, int rows, int cols, cv::Mat &result);
116 
122  static int readMatCSVFloat(boost::filesystem::path file, cv::Mat &result);
123 
128  static int readCSVHeaderString(boost::filesystem::path file, std::vector<std::string> &header);
129 
136  static int readCSVSummary(boost::filesystem::path file, std::vector<std::string>& row_headers,
137  std::vector<std::string>& col_headers, cv::Mat &data);
138 
143  static void listSubdirectories(boost::filesystem::path directory,
144  std::multimap<std::string, boost::filesystem::path> subdirectories);
145 
157  static void readDirectory(boost::filesystem::path directory,
158  std::vector<std::string> extensions,
159  std::multimap<std::string, boost::filesystem::path> &files,
160  std::string prefix = "", std::string suffix = "",
161  std::vector<std::string> exclude = std::vector<std::string>{});
162 
170  static void readDirectory(boost::filesystem::path directory,
171  std::multimap<std::string, boost::filesystem::path> &files,
172  std::string prefix = "", std::string suffix = "");
173 
177  static void getImageExtensions(std::vector<std::string> &extensions);
178 
182  static void getTxtExtensions(std::vector<std::string> &extensions);
183 
187  static void getCSVExtensions(std::vector<std::string> &extensions);
188 
189 };
190 
191 #endif /* IO_UTIL_H */
static int writeMat(boost::filesystem::path file, const cv::Mat &mat, std::string field="mat")
Write a matrix to the given file.
Definition: io_util.cpp:59
static void getImageExtensions(std::vector< std::string > &extensions)
Gets a vector containing common extensions for images.
Definition: io_util.cpp:265
static int readMatCSVInt(boost::filesystem::path file, cv::Mat &result)
Read CSV file into matrix.
Definition: io_util.cpp:301
static int writeArrayCSV(boost::filesystem::path file, T **array, int rows, int cols, std::string separator=",", int precision=6)
Write two dimensional array to CSV file.
Definition: io_util.cpp:75
static int readCSVHeaderString(boost::filesystem::path file, std::vector< std::string > &header)
Read header of CSV file into string array.
Definition: io_util.cpp:409
I/O utilities.
Definition: io_util.h:52
static void getTxtExtensions(std::vector< std::string > &extensions)
Gets a vector containing common extensions for text files.
Definition: io_util.cpp:281
static void readDirectory(boost::filesystem::path directory, std::vector< std::string > extensions, std::multimap< std::string, boost::filesystem::path > &files, std::string prefix="", std::string suffix="", std::vector< std::string > exclude=std::vector< std::string >{})
Creates an ordered multimap of all files in the given directory.
Definition: io_util.cpp:205
static int readMat(boost::filesystem::path file, cv::Mat &mat, std::string field="mat")
Read an OpenCV matrix.
Definition: io_util.cpp:42
static int readMatCSVFloat(boost::filesystem::path file, cv::Mat &result)
Read CSV file into matrix.
Definition: io_util.cpp:355
static void listSubdirectories(boost::filesystem::path directory, std::multimap< std::string, boost::filesystem::path > subdirectories)
Creates an ordered list of all subdirectories.
Definition: io_util.cpp:144
static void getCSVExtensions(std::vector< std::string > &extensions)
Get a vector of common CSV extensions.
Definition: io_util.cpp:291
static int writeMatCSV(boost::filesystem::path file, const cv::Mat &mat, std::string separator=",", int precision=6)
Write the content of a cv::Mat to a CSV file.
Definition: io_util.cpp:107
static int readCSVSummary(boost::filesystem::path file, std::vector< std::string > &row_headers, std::vector< std::string > &col_headers, cv::Mat &data)
Read a CSV summary file as produced by EvaluationSummary.
Definition: io_util.cpp:435