xml_test.cpp
Go to the documentation of this file.
00001 #include <cob_people_detection/subspace_analysis.h>
00002 #include <opencv2/opencv.hpp>
00003 #include <iostream>
00004 #include <fstream>
00005 
00006 int main(int argc, const char *argv[])
00007 {
00008 
00009         std::string file1 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/30.xml";
00010         std::string file2 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/31.xml";
00011         std::string file3 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/32.xml";
00012         std::string file4 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/33.xml";
00013         std::string file5 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/34.xml";
00014         std::string file6 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/35.xml";
00015         std::string file7 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/36.xml";
00016         std::string file8 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/37.xml";
00017         std::string file9 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/38.xml";
00018         std::string file10 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/39.xml";
00019         std::string file11 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/40.xml";
00020         std::string file12 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/41.xml";
00021         std::string file13 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/42.xml";
00022         std::string file14 = "/home/goa-tz/git/care-o-bot/cob_people_perception/cob_people_detection/common/files/training_data/43.xml";
00023 
00024         std::vector < std::string > in_vec;
00025         std::vector<int> label_vec;
00026         in_vec.push_back(file1);
00027         label_vec.push_back(0);
00028         in_vec.push_back(file2);
00029         label_vec.push_back(0);
00030         in_vec.push_back(file3);
00031         label_vec.push_back(0);
00032         in_vec.push_back(file4);
00033         label_vec.push_back(0);
00034         in_vec.push_back(file5);
00035         label_vec.push_back(0);
00036         in_vec.push_back(file6);
00037         label_vec.push_back(0);
00038         in_vec.push_back(file7);
00039         label_vec.push_back(0);
00040         in_vec.push_back(file8);
00041         label_vec.push_back(1);
00042         in_vec.push_back(file9);
00043         label_vec.push_back(1);
00044         in_vec.push_back(file10);
00045         label_vec.push_back(1);
00046         in_vec.push_back(file11);
00047         label_vec.push_back(1);
00048         in_vec.push_back(file12);
00049         label_vec.push_back(1);
00050         in_vec.push_back(file13);
00051         label_vec.push_back(1);
00052         in_vec.push_back(file14);
00053         label_vec.push_back(1);
00054         // std::vector<int> label_vec;
00055         std::vector<cv::Mat> img_vec;
00056 
00057         for (int i = 0; i < in_vec.size(); i++)
00058         {
00059                 cv::Mat img;
00060                 cv::FileStorage fs(in_vec[i], cv::FileStorage::READ);
00061                 fs["depthmap"] >> img;
00062                 //img.convertTo(img,CV_8UC1,255);
00063                 //cv::equalizeHist(img,img);
00064                 //cv::imshow("img",img);
00065                 //cv::waitKey(0);
00066                 cv::resize(img, img, cv::Size(120, 120));
00067                 img.convertTo(img, CV_64FC1);
00068                 img_vec.push_back(img);
00069                 fs.release();
00070 
00071         }
00072 
00073         std::vector<cv::Mat> probe_mat_vec;
00074         probe_mat_vec.push_back(img_vec[0]);
00075 
00076         std::cout << "Size Training Set= " << img_vec.size() << std::endl;
00077 
00078         int ss_dim = 2;
00079         //SubspaceAnalysis::Eigenfaces EF;
00080         // EF.init(img_vec,label_vec,ss_dim);
00081         //std::vector<cv::Mat> eigenvecsEF(ss_dim);
00082         //cv::Mat eigenvalsEF,avgEF,projsEF;
00083         //EF.retrieve(eigenvecsEF,eigenvalsEF,avgEF,projsEF,cv::Size(img_vec[0].cols,img_vec[0].rows));
00084         //SubspaceAnalysis::dump_matrix(projsEF,"projEF");
00085 
00086 
00087         //SubspaceAnalysis::Fisherfaces FF;
00088         // FF.init(img_vec,label_vec);
00089 
00090         //cv::Mat eigenvalsFF,avgFF,projsFF;
00091         //std::vector<cv::Mat> eigenvecsFF(ss_dim);
00092         //FF.retrieve(eigenvecsFF,eigenvalsFF,avgFF,projsFF);
00093         //SubspaceAnalysis::dump_matrix(projsFF,"projFF");
00094 
00095         SubspaceAnalysis::FishEigFaces EFF;
00096 
00097         EFF.init(img_vec, label_vec, ss_dim, SubspaceAnalysis::METH_FISHER, true, true);
00098 
00099         for (int i = 0; i < probe_mat_vec.size(); i++)
00100         {
00101                 cv::Mat probe = probe_mat_vec[i];
00104                 //cv::Mat coeff_FF;
00105                 //int c_FF;
00106                 //double DFFS_FF;
00107                 //FF.projectToSubspace(probe,coeff_FF,DFFS_FF);
00108                 //FF.classify(coeff_FF,SubspaceAnalysis::CLASS_SVM,c_FF);
00109                 //std::cout<<"class FF SVM= "<<c_FF<<std::endl;
00110                 //FF.classify(coeff_FF,SubspaceAnalysis::CLASS_KNN,c_FF);
00111                 //std::cout<<"class FF KNN= "<<c_FF<<std::endl;
00112                 //FF.classify(coeff_FF,SubspaceAnalysis::CLASS_DIFS,c_FF);
00113                 //std::cout<<"class FF DIFFS= "<<c_FF<<std::endl;
00114 
00115                 //SubspaceAnalysis::dump_matrix(coeff_FF,"sampleFF");
00116                 //std::cout<<"--------------------------\n";
00117 
00118                 //int c_EF;
00119                 //cv::Mat coeff_EF;
00120                 //double DFFS_EF;
00121                 //EF.projectToSubspace(probe,coeff_EF,DFFS_EF);
00122                 //EF.classify(coeff_EF,SubspaceAnalysis::CLASS_SVM,c_EF);
00123                 //std::cout<<"class EF SVM= "<<c_EF<<std::endl;
00124                 //EF.classify(coeff_EF,SubspaceAnalysis::CLASS_KNN,c_EF);
00125                 //std::cout<<"class EF KNN= "<<c_EF<<std::endl;
00126                 //EF.classify(coeff_EF,SubspaceAnalysis::CLASS_DIFS,c_EF);
00127                 //std::cout<<"class EF DIFFS= "<<c_EF<<std::endl;
00128 
00129                 //SubspaceAnalysis::dump_matrix(coeff_EF,"sampleEF");
00130 
00131                 //std::cout<<"--------------------------\n";
00132 
00133                 int c_EFF;
00134                 cv::Mat coeff_EFF;
00135                 double DFFS_EFF;
00136                 EFF.projectToSubspace(probe, coeff_EFF, DFFS_EFF);
00137                 EFF.classify(coeff_EFF, SubspaceAnalysis::CLASS_SVM, c_EFF);
00138                 std::cout << "class EFF SVM= " << c_EFF << std::endl;
00139                 EFF.classify(coeff_EFF, SubspaceAnalysis::CLASS_KNN, c_EFF);
00140                 std::cout << "class EFF KNN= " << c_EFF << std::endl;
00141                 EFF.classify(coeff_EFF, SubspaceAnalysis::CLASS_DIFS, c_EFF);
00142                 std::cout << "class EFF DIFFS= " << c_EFF << std::endl;
00143 
00144                 SubspaceAnalysis::dump_matrix(coeff_EFF, "sampleEFF");
00145         }
00146 
00147         return 0;
00148 }


cob_people_detection
Author(s): Richard Bormann , Thomas Zwölfer
autogenerated on Mon May 6 2019 02:32:06