48 #include <boost/format.hpp> 51 using namespace shark;
56 const char *facedirectory =
"Cambridge_FaceDB";
58 cout <<
"Read images ... " << flush;
62 cerr <<
"[PCATutorial] could not open face database directory\n\nThis file is part of the \"Principal Component Analysis\" tutorial.\nThe tutorial requires that you download the Cambridge Face Database\nfrom http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html\nand adjust the facedirectory path in the source code to the directory\ncontaining the faces in PGM format." << endl;
65 cout <<
"done." << endl;
68 unsigned x = images.
shape()[1];
69 unsigned y = images.
shape()[0];
71 cout <<
"Eigenvalue decomposition ... " << flush;
73 cout <<
"done." << endl;
75 cout <<
"Writing mean face and eigenvalues... " << flush;
76 ofstream ofs(
"facesEigenvalues.csv");
77 for(
unsigned i=0; i<l; i++)
80 cout <<
"done. " << endl;
82 cout <<
"Encoding ... " << flush;
87 cout <<
"done. " << endl;
89 unsigned sampleImage = 0;
90 cout <<
"Reconstructing face " << sampleImage <<
" ... " << flush;
91 boost::format fmterTrue(
"face%d.pgm");
92 exportPGM((fmterTrue % sampleImage).str().c_str(), images.
element(sampleImage), x, y);
95 boost::format fmterRec(
"facesReconstruction%d-%d.pgm");
96 exportPGM((fmterRec % sampleImage % m).str().c_str(), dec(encodedImages.
element(sampleImage)), x, y);
97 cout <<
"done." << endl;