IO.h
Go to the documentation of this file.
00001 
00010 #ifndef __D_CV_IO__
00011 #define __D_CV_IO__
00012 
00013 #include <iostream>
00014 #include <vector>
00015 #include <opencv/cv.h>
00016 #include <opencv2/legacy/legacy.hpp>
00017 #include <string>
00018 
00019 namespace DUtilsCV
00020 {
00021 
00022 class IO
00023 {
00024 public:
00025 
00033   static void saveKeyPoints(const std::string &filename,
00034     const std::vector<cv::KeyPoint> &keys,
00035     const std::string &nodename = "keys");
00036   
00043   static void loadKeyPoints(const std::string &filename,
00044     std::vector<cv::KeyPoint> &keys,
00045     const std::string &nodename = "keys");
00046   
00053   static void print(const cv::Mat &m,
00054     const std::string &name = "", std::ostream &f = std::cout);
00055   
00062   template<class T>
00063   static void print(const cv::Mat &m, 
00064     const std::string &name = "", std::ostream &f = std::cout);
00065   
00072   template<class T>
00073   static void save(const std::string &filename, const T& c,
00074     const std::string &nodename = "data");
00075 
00082   template<class T>
00083   static void load(const std::string &filename, T& c,
00084     const std::string &nodename = "data");
00085   
00087   inline static void save(const std::string &filename, 
00088     const cv::FernClassifier &c,
00089     const std::string &nodename = "fern_classifier");
00090 
00091   inline static void load(const std::string &filename, 
00092     cv::FernClassifier &c,
00093     const std::string &nodename = "fern_classifier");
00094   
00095 };
00096 
00097 // ---------------------------------------------------------------------------
00098 
00099 template<class T>
00100 void IO::print(const cv::Mat &m, const std::string &name, std::ostream &f)
00101 {
00102   if(!name.empty()) f << name << " = ";
00103   f << "[ ";
00104   for(int r = 0; r < m.rows; ++r)
00105   {
00106     for(int c = 0; c < m.cols; ++c)
00107     {
00108       f << m.at<T>(r, c) << " ";
00109     }
00110     f << std::endl;
00111   }
00112   f << "]" << std::endl;
00113 }
00114 
00115 // ---------------------------------------------------------------------------
00116 
00117 template<class T>
00118 void IO::save(const std::string &filename, const T& c,
00119   const std::string &nodename)
00120 {
00121   cv::FileStorage fs(filename, cv::FileStorage::WRITE);
00122   c.write(fs, nodename);
00123 }
00124 
00125 // ---------------------------------------------------------------------------
00126 
00127 template<class T>
00128 void IO::load(const std::string &filename, T& c,
00129   const std::string &nodename)
00130 {
00131   cv::FileStorage fs(filename, cv::FileStorage::READ);
00132   c.read(fs[nodename]);
00133 }
00134 
00135 // ---------------------------------------------------------------------------
00136 
00137 inline void IO::save(const std::string &filename, 
00138     const cv::FernClassifier &c,
00139     const std::string &nodename)
00140 {
00141   IO::save<cv::FernClassifier>(filename, c, nodename);
00142 }
00143 
00144 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00145 
00146 inline void IO::load(const std::string &filename, 
00147     cv::FernClassifier &c,
00148     const std::string &nodename)
00149 {
00150   IO::load<cv::FernClassifier>(filename, c, nodename);
00151 }
00152 
00153 // ---------------------------------------------------------------------------
00154 
00155 }
00156 
00157 #endif
00158 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:29