Commit 4041650f authored by dmitriy.anisimov's avatar dmitriy.anisimov

updated fr_lfw dataset loader

parent 5624ad2c
...@@ -50,13 +50,13 @@ FR_lfw ...@@ -50,13 +50,13 @@ FR_lfw
Implements loading dataset: Implements loading dataset:
_`"Labeled Faces in the Wild-a"`: http://www.openu.ac.il/home/hassner/data/lfwa/ _`"Labeled Faces in the Wild"`: http://vis-www.cs.umass.edu/lfw/
.. note:: Usage .. note:: Usage
1. From link above download dataset file: lfwa.tar.gz. 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.
2. Unpack it. 2. Unpack dataset file and place pairs.txt in created folder.
3. To load data run: ./opencv/build/bin/example_datasetstools_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ 3. To load data run: ./opencv/build/bin/example_datasetstools_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/
......
...@@ -56,8 +56,8 @@ namespace datasetstools ...@@ -56,8 +56,8 @@ namespace datasetstools
struct FR_lfwObj : public Object struct FR_lfwObj : public Object
{ {
std::string name; std::string image1, image2;
std::vector<std::string> images; bool same;
}; };
class CV_EXPORTS FR_lfw : public Dataset class CV_EXPORTS FR_lfw : public Dataset
......
...@@ -72,6 +72,9 @@ int main(int argc, char *argv[]) ...@@ -72,6 +72,9 @@ int main(int argc, char *argv[])
// dataset contains for each split: a set of video file names for each action. // dataset contains for each split: a set of video file names for each action.
// For example, let output all training video file names for second split and first action. // For example, let output all training video file names for second split and first action.
// And its size. // And its size.
int numSplits = dataset->getNumSplits();
printf("splits number: %u\n", numSplits);
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset->getTrain(1)[0].get()); AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset->getTrain(1)[0].get());
printf("name: %s\n", example->name.c_str()); printf("name: %s\n", example->name.c_str());
vector<string> &videoNames = example->videoNames; vector<string> &videoNames = example->videoNames;
......
...@@ -69,16 +69,21 @@ int main(int argc, char *argv[]) ...@@ -69,16 +69,21 @@ int main(int argc, char *argv[])
dataset->load(path); dataset->load(path);
// *************** // ***************
// dataset contains object with name and its images. // test contains two images and flag that they belong to one person.
// For example, let output dataset size and sixth element. // For example, let output splits number, test size and split 1, elements: 1, 301.
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); int numSplits = dataset->getNumSplits();
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset->getTrain()[5].get()); printf("splits number: %u\n", numSplits);
printf("sixth dataset object:\n%s\n", example->name.c_str()); printf("test size: %u\n", (unsigned int)dataset->getTest().size());
string currPath(path + example->name + "/");
for (vector<string>::iterator it=example->images.begin(); it!=example->images.end(); ++it) FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset->getTest()[0].get());
{ printf("first test, first image: %s\n", example->image1.c_str());
printf("%s\n", (currPath+(*it)).c_str()); printf("first test, second image: %s\n", example->image2.c_str());
} printf("first test, same: %s\n", example->same?"yes":"no");
example = static_cast<FR_lfwObj *>(dataset->getTest()[300].get());
printf("300 test, first image: %s\n", example->image1.c_str());
printf("300 test, second image: %s\n", example->image2.c_str());
printf("300 test, same: %s\n", example->same?"yes":"no");
return 0; return 0;
} }
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "opencv2/datasetstools/fr_lfw.hpp" #include "opencv2/datasetstools/fr_lfw.hpp"
#include "precomp.hpp" #include "precomp.hpp"
#include <map>
namespace cv namespace cv
{ {
namespace datasetstools namespace datasetstools
...@@ -60,6 +62,8 @@ public: ...@@ -60,6 +62,8 @@ public:
private: private:
void loadDataset(const string &path); void loadDataset(const string &path);
map< string, vector<string> > faces;
}; };
/*FR_lfwImp::FR_lfwImp(const string &path) /*FR_lfwImp::FR_lfwImp(const string &path)
...@@ -74,26 +78,69 @@ void FR_lfwImp::load(const string &path) ...@@ -74,26 +78,69 @@ void FR_lfwImp::load(const string &path)
void FR_lfwImp::loadDataset(const string &path) void FR_lfwImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
vector<string> fileNames; vector<string> fileNames;
getDirList(path, fileNames); getDirList(path, fileNames);
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it)
{ {
Ptr<FR_lfwObj> curr(new FR_lfwObj); if ("pairs.txt" == *it)
curr->name = *it; {
continue;
}
string pathFace(path + curr->name + "/"); string &name = *it;
vector<string> images;
string pathFace(path + name + "/");
vector<string> faceNames; vector<string> faceNames;
getDirList(pathFace, faceNames); getDirList(pathFace, faceNames);
for (vector<string>::iterator itFace=faceNames.begin(); itFace!=faceNames.end(); ++itFace) for (vector<string>::iterator itFace=faceNames.begin(); itFace!=faceNames.end(); ++itFace)
{ {
curr->images.push_back(*itFace); images.push_back(*itFace);
} }
train.back().push_back(curr); faces.insert(make_pair(name, images));
}
// test loading
ifstream infile((path + "pairs.txt").c_str());
string line;
getline(infile, line); // should be 10 300
unsigned int num = 0;
while (getline(infile, line))
{
if (0 == (num % 600))
{
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
}
vector<string> elems;
split(line, elems, '\t');
Ptr<FR_lfwObj> curr(new FR_lfwObj);
string &person1 = elems[0];
unsigned int imageNumber1 = atoi(elems[1].c_str())-1;
curr->image1 = person1 + "/" + faces[person1][imageNumber1];
string person2;
unsigned int imageNumber2;
if (3 == elems.size())
{
person2 = elems[0];
imageNumber2 = atoi(elems[2].c_str())-1;
curr->same = true;
} else
{
person2 = elems[2];
imageNumber2 = atoi(elems[3].c_str())-1;
curr->same = false;
}
curr->image2 = person2 + "/" + faces[person2][imageNumber2];
test.back().push_back(curr);
num++;
} }
} }
......
set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection") set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection")
ocv_define_module(xfeatures2d opencv_core opencv_cudaarithm opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml) ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml opencv_cudaarithm)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment