00001
00024 #ifndef __D_CV_IO__
00025 #define __D_CV_IO__
00026
00027 #include <iostream>
00028 #include <vector>
00029 #include <opencv/cv.h>
00030 #include <opencv2/legacy/legacy.hpp>
00031 #include <string>
00032
00033 namespace DUtilsCV
00034 {
00035
00037 class IO
00038 {
00039 public:
00040
00048 static void saveKeyPoints(const std::string &filename,
00049 const std::vector<cv::KeyPoint> &keys,
00050 const std::string &nodename = "keys");
00051
00058 static void loadKeyPoints(const std::string &filename,
00059 std::vector<cv::KeyPoint> &keys,
00060 const std::string &nodename = "keys");
00061
00068 static void print(const cv::Mat &m,
00069 const std::string &name = "", std::ostream &f = std::cout);
00070
00077 template<class T>
00078 static void print(const cv::Mat &m,
00079 const std::string &name = "", std::ostream &f = std::cout);
00080
00087 static void printSize(const cv::Mat &m,
00088 const std::string &name = "", std::ostream &f = std::cout);
00089
00096 static void printType(const cv::Mat &m,
00097 const std::string &name = "", std::ostream &f = std::cout);
00098
00105 template<class T>
00106 static void save(const std::string &filename, const T& c,
00107 const std::string &nodename = "data");
00108
00115 template<class T>
00116 static void load(const std::string &filename, T& c,
00117 const std::string &nodename = "data");
00118
00119
00120
00127 inline static void save(const std::string &filename,
00128 const cv::FernClassifier &c,
00129 const std::string &nodename = "fern_classifier");
00130
00137 inline static void load(const std::string &filename,
00138 cv::FernClassifier &c,
00139 const std::string &nodename = "fern_classifier");
00140
00141 };
00142
00143
00144
00145 template<class T>
00146 void IO::print(const cv::Mat &m, const std::string &name, std::ostream &f)
00147 {
00148 if(!name.empty()) f << name << " = ";
00149 f << "[ " << std::endl;
00150 for(int r = 0; r < m.rows; ++r)
00151 {
00152 for(int c = 0; c < m.cols; ++c)
00153 {
00154 f << m.at<T>(r, c) << " ";
00155 }
00156 f << std::endl;
00157 }
00158 f << "]" << std::endl;
00159 }
00160
00161
00162
00163 template<class T>
00164 void IO::save(const std::string &filename, const T& c,
00165 const std::string &nodename)
00166 {
00167 cv::FileStorage fs(filename, cv::FileStorage::WRITE);
00168 c.write(fs, nodename);
00169 }
00170
00171
00172
00173 template<class T>
00174 void IO::load(const std::string &filename, T& c,
00175 const std::string &nodename)
00176 {
00177 cv::FileStorage fs(filename, cv::FileStorage::READ);
00178 c.read(fs[nodename]);
00179 }
00180
00181
00182
00183 inline void IO::save(const std::string &filename,
00184 const cv::FernClassifier &c,
00185 const std::string &nodename)
00186 {
00187 IO::save<cv::FernClassifier>(filename, c, nodename);
00188 }
00189
00190
00191
00192 inline void IO::load(const std::string &filename,
00193 cv::FernClassifier &c,
00194 const std::string &nodename)
00195 {
00196 IO::load<cv::FernClassifier>(filename, c, nodename);
00197 }
00198
00199
00200
00201 }
00202
00203 #endif
00204