Skip to content

Commit 4041650

Browse files
author
dmitriy.anisimov
committed
updated fr_lfw dataset loader
1 parent 5624ad2 commit 4041650

File tree

6 files changed

+80
-25
lines changed

6 files changed

+80
-25
lines changed

modules/datasetstools/doc/datasetstools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ FR_lfw
5050
5151
Implements loading dataset:
5252

53-
_`"Labeled Faces in the Wild-a"`: http://www.openu.ac.il/home/hassner/data/lfwa/
53+
_`"Labeled Faces in the Wild"`: http://vis-www.cs.umass.edu/lfw/
5454

5555
.. note:: Usage
5656

57-
1. From link above download dataset file: lfwa.tar.gz.
57+
1. From link above download any dataset file: lfw.tgz\lfwa.tar.gz\lfw-deepfunneled.tgz\lfw-funneled.tgz and file with 10 test splits: pairs.txt.
5858

59-
2. Unpack it.
59+
2. Unpack dataset file and place pairs.txt in created folder.
6060

6161
3. To load data run: ./opencv/build/bin/example_datasetstools_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/
6262

modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ namespace datasetstools
5656

5757
struct FR_lfwObj : public Object
5858
{
59-
std::string name;
60-
std::vector<std::string> images;
59+
std::string image1, image2;
60+
bool same;
6161
};
6262

6363
class CV_EXPORTS FR_lfw : public Dataset

modules/datasetstools/samples/ar_hmdb.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ int main(int argc, char *argv[])
7272
// dataset contains for each split: a set of video file names for each action.
7373
// For example, let output all training video file names for second split and first action.
7474
// And its size.
75+
int numSplits = dataset->getNumSplits();
76+
printf("splits number: %u\n", numSplits);
77+
7578
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset->getTrain(1)[0].get());
7679
printf("name: %s\n", example->name.c_str());
7780
vector<string> &videoNames = example->videoNames;

modules/datasetstools/samples/fr_lfw.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ int main(int argc, char *argv[])
6969
dataset->load(path);
7070

7171
// ***************
72-
// dataset contains object with name and its images.
73-
// For example, let output dataset size and sixth element.
74-
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
75-
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset->getTrain()[5].get());
76-
printf("sixth dataset object:\n%s\n", example->name.c_str());
77-
string currPath(path + example->name + "/");
78-
for (vector<string>::iterator it=example->images.begin(); it!=example->images.end(); ++it)
79-
{
80-
printf("%s\n", (currPath+(*it)).c_str());
81-
}
72+
// test contains two images and flag that they belong to one person.
73+
// For example, let output splits number, test size and split 1, elements: 1, 301.
74+
int numSplits = dataset->getNumSplits();
75+
printf("splits number: %u\n", numSplits);
76+
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
77+
78+
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset->getTest()[0].get());
79+
printf("first test, first image: %s\n", example->image1.c_str());
80+
printf("first test, second image: %s\n", example->image2.c_str());
81+
printf("first test, same: %s\n", example->same?"yes":"no");
82+
83+
example = static_cast<FR_lfwObj *>(dataset->getTest()[300].get());
84+
printf("300 test, first image: %s\n", example->image1.c_str());
85+
printf("300 test, second image: %s\n", example->image2.c_str());
86+
printf("300 test, same: %s\n", example->same?"yes":"no");
8287

8388
return 0;
8489
}

modules/datasetstools/src/fr_lfw.cpp

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "opencv2/datasetstools/fr_lfw.hpp"
4343
#include "precomp.hpp"
4444

45+
#include <map>
46+
4547
namespace cv
4648
{
4749
namespace datasetstools
@@ -60,6 +62,8 @@ class CV_EXPORTS FR_lfwImp : public FR_lfw
6062

6163
private:
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

7579
void 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

modules/xfeatures2d/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection")
2-
ocv_define_module(xfeatures2d opencv_core opencv_cudaarithm opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml)
2+
ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml opencv_cudaarithm)

0 commit comments

Comments
 (0)