subspace_analysis.h
Go to the documentation of this file.
00001 #ifndef SSA_H_
00002 #define SSA_H_
00003 
00004 #include<opencv/cv.h>
00005 #include<iostream>
00006 #include<opencv/highgui.h>
00007 #include<opencv/ml.h>
00008 #include<fstream>
00009 #include<ostream>
00010 #include<limits>
00011 
00012 #include<math.h>
00013 namespace SubspaceAnalysis
00014 {
00015 
00016 //Baseclass for PCA LDA
00017 class SSA
00018 {
00019 
00020 public:
00021         SSA()
00022         {
00023         }
00024         ;
00025 
00026         virtual ~SSA()
00027         {
00028         }
00029         ;
00030         void calcDataMat(std::vector<cv::Mat>& input_data, cv::Mat& data_mat);
00031         void calcDataMatMean(cv::Mat& data, cv::Mat& mean_row);
00032         void decomposeSVD(cv::Mat& data_mat);
00033         void decomposeSymmetricMatrix(cv::Mat& data_mat);
00034         void decomposeAsymmetricMatrix(cv::Mat& data_mat);
00035         //Interface methods
00036         void retrieve(cv::Mat& proj, cv::Mat& avg, cv::Mat& proj_model_data);
00037 
00038         cv::Mat eigenvals;
00039         cv::Mat eigenvecs;
00040         cv::Mat mean;
00041         int ss_dim_;
00042 };
00043 
00044 class PCA2D: public SSA
00045 {
00046 
00047 public:
00048         PCA2D()
00049         {
00050         }
00051         ;
00052         PCA2D(std::vector<cv::Mat>& input_data, std::vector<int>& input_labels, int& num_classes, int& ss_dim);
00053         virtual ~PCA2D()
00054         {
00055         }
00056         ;
00057 
00058         int num_classes_;
00059         std::vector<int> unique_labels_;
00060 
00061         cv::Mat class_mean_arr;
00062 };
00063 class LDA2D: public SSA
00064 {
00065 
00066 public:
00067         LDA2D()
00068         {
00069         }
00070         ;
00071         LDA2D(std::vector<cv::Mat>& input_data, std::vector<int>& input_labels, int& num_classes, int& ss_dim);
00072         virtual ~LDA2D()
00073         {
00074         }
00075         ;
00076 
00077         int num_classes_;
00078         std::vector<int> unique_labels_;
00079 
00080         cv::Mat class_mean_arr;
00081 };
00082 
00083 class LDA: public SSA
00084 {
00085 
00086 public:
00087         LDA()
00088         {
00089         }
00090         ;
00091         LDA(cv::Mat& input_data, std::vector<int>& input_labels, int& num_classes, int& ss_dim);
00092         virtual ~LDA()
00093         {
00094         }
00095         ;
00096 
00097         void calcClassMean(cv::Mat& data_mat, std::vector<int>& label_vec, cv::Mat& class_mean_arr, int& num_classes);
00098         void calcClassMean(cv::Mat& data_mat, cv::Mat& label_mat, cv::Mat& class_mean_arr, int& num_classes);
00099         virtual void calcProjMatrix(cv::Mat& data_arr, std::vector<int>& label_vec);
00100 
00101         int num_classes_;
00102         std::vector<int> unique_labels_;
00103 
00104         cv::Mat class_mean_arr;
00105 };
00106 
00107 class ILDA: public LDA
00108 {
00109 public:
00110         ILDA()
00111         {
00112         }
00113         ;
00114         ILDA(cv::Mat& input_data, std::vector<int>& input_labels, int& num_classes, int& ss_dim);
00115         virtual ~ILDA()
00116         {
00117         }
00118         ;
00119 
00120         virtual void calcProjMatrix(cv::Mat& data_arr, std::vector<int>& label_vec);
00121 
00122 };
00123 
00124 class PCA: public SSA
00125 {
00126 public:
00127         PCA()
00128         {
00129         }
00130         ;
00131         PCA(cv::Mat& input_data, int& ss_dim);
00132         virtual ~PCA()
00133         {
00134         }
00135         ;
00136         virtual void calcProjMatrix(cv::Mat& data);
00137         void PCA_OpenCv(cv::Mat& input_data, int& ss_dim);
00138 };
00139 
00140 // Base class for SubSpace Analysis(SSA)
00141 //
00142 //
00143 //
00144 //
00145 //
00146 //
00147 void dump_matrix(cv::Mat& mat, std::string filename);
00148 void condense_labels(std::vector<int>& labels);
00149 
00150 void error_prompt(std::string fct, std::string desc);
00151 void unique_elements(std::vector<int> & vec, int& unique_elements, std::vector<int>& distinct_vec);
00152 void unique_elements(cv::Mat & mat, int& unique_elements, std::vector<int>& distinct_vec);
00153 
00154 void mat_info(cv::Mat& mat);
00155 void mat2arr(cv::Mat& src_mat, cv::Mat& dst_mat);
00156 
00157 template<class T>
00158 void process_labels(std::vector<T> src_vec, cv::Mat& dst_labels)
00159 {
00160 
00161         dst_labels = cv::Mat::zeros(1, src_vec.size(), CV_32FC1);
00162         dst_labels -= 1;
00163         bool unique;
00164         for (int i = 0; i < src_vec.size(); ++i)
00165         {
00166                 unique = true;
00167                 for (int j = 0; j < dst_labels.rows; j++)
00168                 {
00169                         if (i == 0)
00170                         {
00171                                 break;
00172                         }
00173                         else if (src_vec[i] == src_vec[j])
00174                         {
00175                                 unique = false;
00176                                 dst_labels.at<float>(i) = dst_labels.at<float>(j);
00177                                 break;
00178                         }
00179                         else
00180                                 continue;
00181                 }
00182                 if (unique == true)
00183                         dst_labels.at<float>(i) = (float)i;
00184         }
00185 
00186 }
00187 
00188 }
00189 ;
00190 #endif


cob_people_detection
Author(s): Richard Bormann , Thomas Zwölfer
autogenerated on Fri Aug 28 2015 10:24:13