mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 04:25:42 +08:00
added fr_adience dataset loader
This commit is contained in:
93
modules/datasets/include/opencv2/datasets/fr_adience.hpp
Normal file
93
modules/datasets/include/opencv2/datasets/fr_adience.hpp
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_DATASETS_FR_ADIENCE_HPP
|
||||||
|
#define OPENCV_DATASETS_FR_ADIENCE_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "opencv2/datasets/dataset.hpp"
|
||||||
|
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
namespace cv
|
||||||
|
{
|
||||||
|
namespace datasets
|
||||||
|
{
|
||||||
|
|
||||||
|
enum genderType
|
||||||
|
{
|
||||||
|
male = 0,
|
||||||
|
female,
|
||||||
|
none
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FR_adienceObj : public Object
|
||||||
|
{
|
||||||
|
std::string user_id;
|
||||||
|
std::string original_image;
|
||||||
|
int face_id;
|
||||||
|
std::string age;
|
||||||
|
genderType gender;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
|
int tilt_ang;
|
||||||
|
int fiducial_yaw_angle;
|
||||||
|
int fiducial_score;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CV_EXPORTS FR_adience : public Dataset
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void load(const std::string &path) = 0;
|
||||||
|
|
||||||
|
static Ptr<FR_adience> create();
|
||||||
|
|
||||||
|
std::vector<std::string> paths;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
105
modules/datasets/samples/fr_adience.cpp
Normal file
105
modules/datasets/samples/fr_adience.cpp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#include "opencv2/datasets/fr_adience.hpp"
|
||||||
|
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
using namespace cv::datasets;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const char *keys =
|
||||||
|
"{ help h usage ? | | show this message }"
|
||||||
|
"{ path p |true| path to dataset folder and splits }";
|
||||||
|
CommandLineParser parser(argc, argv, keys);
|
||||||
|
string path(parser.get<string>("path"));
|
||||||
|
if (parser.has("help") || path=="true")
|
||||||
|
{
|
||||||
|
parser.printMessage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr<FR_adience> dataset = FR_adience::create();
|
||||||
|
dataset->load(path);
|
||||||
|
|
||||||
|
// ***************
|
||||||
|
// dataset contains for each object its images.
|
||||||
|
// For example, let output splits number, dataset size and last image.
|
||||||
|
int numSplits = dataset->getNumSplits();
|
||||||
|
printf("splits number: %u\n", numSplits);
|
||||||
|
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||||
|
|
||||||
|
FR_adienceObj *example = static_cast<FR_adienceObj *>(dataset->getTrain().back().get());
|
||||||
|
printf("last image:\n");
|
||||||
|
printf("user_id: %s\n", example->user_id.c_str());
|
||||||
|
printf("original_image: %s\n", example->original_image.c_str());
|
||||||
|
printf("face_id: %u\n", example->face_id);
|
||||||
|
printf("age: %s\n", example->age.c_str());
|
||||||
|
printf("gender: ");
|
||||||
|
if (example->gender == male)
|
||||||
|
{
|
||||||
|
printf("m\n");
|
||||||
|
} else
|
||||||
|
if (example->gender == female)
|
||||||
|
{
|
||||||
|
printf("f\n");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("none\n");
|
||||||
|
}
|
||||||
|
printf("x: %u\n", example->x);
|
||||||
|
printf("y: %u\n", example->y);
|
||||||
|
printf("dx: %u\n", example->dx);
|
||||||
|
printf("dy: %u\n", example->dy);
|
||||||
|
printf("tilt_ang: %u\n", example->tilt_ang);
|
||||||
|
printf("fiducial_yaw_angle: %u\n", example->fiducial_yaw_angle);
|
||||||
|
printf("fiducial_score: %u\n", example->fiducial_score);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
175
modules/datasets/src/fr_adience.cpp
Normal file
175
modules/datasets/src/fr_adience.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#include "opencv2/datasets/fr_adience.hpp"
|
||||||
|
#include "opencv2/datasets/util.hpp"
|
||||||
|
#include "precomp.hpp"
|
||||||
|
|
||||||
|
namespace cv
|
||||||
|
{
|
||||||
|
namespace datasets
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class CV_EXPORTS FR_adienceImp : public FR_adience
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FR_adienceImp() {}
|
||||||
|
//FR_adienceImp(const string &path);
|
||||||
|
virtual ~FR_adienceImp() {}
|
||||||
|
|
||||||
|
virtual void load(const string &path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadDataset(const string &path);
|
||||||
|
|
||||||
|
void loadFile(const string &filename, vector< Ptr<FR_adienceObj> > &out);
|
||||||
|
void cv5ToSplits(vector< Ptr<FR_adienceObj> > fileList[5]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*FR_adienceImp::FR_adienceImp(const string &path)
|
||||||
|
{
|
||||||
|
loadDataset(path);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void FR_adienceImp::load(const string &path)
|
||||||
|
{
|
||||||
|
loadDataset(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FR_adienceImp::loadFile(const string &filename, vector< Ptr<FR_adienceObj> > &out)
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
ifstream infile(filename.c_str());
|
||||||
|
while (getline(infile, line))
|
||||||
|
{
|
||||||
|
Ptr<FR_adienceObj> curr(new FR_adienceObj);
|
||||||
|
|
||||||
|
vector<string> elems;
|
||||||
|
split(line, elems, ',');
|
||||||
|
|
||||||
|
curr->user_id = elems[0];
|
||||||
|
curr->original_image = elems[1];
|
||||||
|
curr->face_id = atoi(elems[2].c_str());
|
||||||
|
curr->age = elems[3];
|
||||||
|
if (elems[4]=="m")
|
||||||
|
{
|
||||||
|
curr->gender = male;
|
||||||
|
} else
|
||||||
|
if (elems[4]=="f")
|
||||||
|
{
|
||||||
|
curr->gender = female;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
curr->gender = none;
|
||||||
|
}
|
||||||
|
curr->x = atoi(elems[5].c_str());
|
||||||
|
curr->y = atoi(elems[6].c_str());
|
||||||
|
curr->dx = atoi(elems[7].c_str());
|
||||||
|
curr->dy = atoi(elems[8].c_str());
|
||||||
|
curr->tilt_ang = atoi(elems[9].c_str());
|
||||||
|
curr->fiducial_yaw_angle = atoi(elems[10].c_str());
|
||||||
|
curr->fiducial_score = atoi(elems[11].c_str());
|
||||||
|
|
||||||
|
out.push_back(curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FR_adienceImp::cv5ToSplits(vector< Ptr<FR_adienceObj> > fileList[5])
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<5; ++i)
|
||||||
|
{
|
||||||
|
train.push_back(vector< Ptr<Object> >());
|
||||||
|
test.push_back(vector< Ptr<Object> >());
|
||||||
|
validation.push_back(vector< Ptr<Object> >());
|
||||||
|
for (unsigned int j=0; j<5; ++j)
|
||||||
|
{
|
||||||
|
vector< Ptr<FR_adienceObj> > &currlist = fileList[j];
|
||||||
|
if (i!=j)
|
||||||
|
{
|
||||||
|
for (vector< Ptr<FR_adienceObj> >::iterator it=currlist.begin(); it!=currlist.end(); ++it)
|
||||||
|
{
|
||||||
|
train.back().push_back(*it);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
for (vector< Ptr<FR_adienceObj> >::iterator it=currlist.begin(); it!=currlist.end(); ++it)
|
||||||
|
{
|
||||||
|
test.back().push_back(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FR_adienceImp::loadDataset(const string &path)
|
||||||
|
{
|
||||||
|
vector< Ptr<FR_adienceObj> > fileList[5];
|
||||||
|
for (unsigned int i=0; i<5; ++i)
|
||||||
|
{
|
||||||
|
char tmp[3];
|
||||||
|
sprintf(tmp, "%u", i);
|
||||||
|
string filename(path+"fold_"+string(tmp)+"_data.txt");
|
||||||
|
|
||||||
|
loadFile(filename, fileList[i]);
|
||||||
|
}
|
||||||
|
cv5ToSplits(fileList);
|
||||||
|
|
||||||
|
for (unsigned int i=0; i<5; ++i)
|
||||||
|
{
|
||||||
|
char tmp[3];
|
||||||
|
sprintf(tmp, "%u", i);
|
||||||
|
string filename(path+"fold_frontal_"+string(tmp)+"_data.txt");
|
||||||
|
|
||||||
|
fileList[i].clear();
|
||||||
|
loadFile(filename, fileList[i]);
|
||||||
|
}
|
||||||
|
cv5ToSplits(fileList);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr<FR_adience> FR_adience::create()
|
||||||
|
{
|
||||||
|
return Ptr<FR_adienceImp>(new FR_adienceImp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user