4242#include " opencv2/datasetstools/fr_lfw.hpp"
4343#include " precomp.hpp"
4444
45+ #include < map>
46+
4547namespace cv
4648{
4749namespace datasetstools
@@ -60,6 +62,8 @@ class CV_EXPORTS FR_lfwImp : public FR_lfw
6062
6163private:
6264 void loadDataset (const string &path);
65+
66+ map< string, vector<string> > faces;
6367};
6468
6569/* FR_lfwImp::FR_lfwImp(const string &path)
@@ -74,26 +78,69 @@ void FR_lfwImp::load(const string &path)
7478
7579void FR_lfwImp::loadDataset (const string &path)
7680{
77- train.push_back (vector< Ptr<Object> >());
78- test.push_back (vector< Ptr<Object> >());
79- validation.push_back (vector< Ptr<Object> >());
80-
8181 vector<string> fileNames;
8282 getDirList (path, fileNames);
8383 for (vector<string>::iterator it=fileNames.begin (); it!=fileNames.end (); ++it)
8484 {
85- Ptr<FR_lfwObj> curr (new FR_lfwObj);
86- curr->name = *it;
85+ if (" pairs.txt" == *it)
86+ {
87+ continue ;
88+ }
8789
88- string pathFace (path + curr->name + " /" );
90+ string &name = *it;
91+ vector<string> images;
92+
93+ string pathFace (path + name + " /" );
8994 vector<string> faceNames;
9095 getDirList (pathFace, faceNames);
9196 for (vector<string>::iterator itFace=faceNames.begin (); itFace!=faceNames.end (); ++itFace)
9297 {
93- curr-> images .push_back (*itFace);
98+ images.push_back (*itFace);
9499 }
95100
96- train.back ().push_back (curr);
101+ faces.insert (make_pair (name, images));
102+ }
103+
104+ // test loading
105+ ifstream infile ((path + " pairs.txt" ).c_str ());
106+ string line;
107+ getline (infile, line); // should be 10 300
108+ unsigned int num = 0 ;
109+ while (getline (infile, line))
110+ {
111+ if (0 == (num % 600 ))
112+ {
113+ train.push_back (vector< Ptr<Object> >());
114+ test.push_back (vector< Ptr<Object> >());
115+ validation.push_back (vector< Ptr<Object> >());
116+ }
117+
118+ vector<string> elems;
119+ split (line, elems, ' \t ' );
120+
121+ Ptr<FR_lfwObj> curr (new FR_lfwObj);
122+ string &person1 = elems[0 ];
123+ unsigned int imageNumber1 = atoi (elems[1 ].c_str ())-1 ;
124+ curr->image1 = person1 + " /" + faces[person1][imageNumber1];
125+
126+ string person2;
127+ unsigned int imageNumber2;
128+ if (3 == elems.size ())
129+ {
130+ person2 = elems[0 ];
131+ imageNumber2 = atoi (elems[2 ].c_str ())-1 ;
132+ curr->same = true ;
133+ } else
134+ {
135+ person2 = elems[2 ];
136+ imageNumber2 = atoi (elems[3 ].c_str ())-1 ;
137+ curr->same = false ;
138+ }
139+ curr->image2 = person2 + " /" + faces[person2][imageNumber2];
140+
141+ test.back ().push_back (curr);
142+
143+ num++;
97144 }
98145}
99146
0 commit comments