Commit 444480df authored by dmitriy.anisimov's avatar dmitriy.anisimov

several enhancements

parent 7597e46e
...@@ -75,9 +75,11 @@ _`"ChaLearn Looking at People"`: http://gesture.chalearn.org/ ...@@ -75,9 +75,11 @@ _`"ChaLearn Looking at People"`: http://gesture.chalearn.org/
1. Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": Train1.zip-Train5.zip, Validation1.zip-Validation3.zip (Register on site: www.codalab.org and accept the terms and conditions of competition: https://www.codalab.org/competitions/991#learn_the_details There are three mirrors for downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" works). 1. Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": Train1.zip-Train5.zip, Validation1.zip-Validation3.zip (Register on site: www.codalab.org and accept the terms and conditions of competition: https://www.codalab.org/competitions/991#learn_the_details There are three mirrors for downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" works).
2. Unpack train archives Train1.zip-Train5.zip to one folder (currently loading validation files wasn't implemented) 2. Unpack train archives Train1.zip-Train5.zip to folder Train/, validation archives Validation1.zip-Validation3.zip to folder Validation/
3. To load data run: ./opencv/build/bin/example_datasetstools_gr_chalearn -p=/home/user/path_to_unpacked_folder/ 3. Unpack all archives in Train/ & Validation/ in the folders with the same names, for example: Sample0001.zip to Sample0001/
4. To load data run: ./opencv/build/bin/example_datasetstools_gr_chalearn -p=/home/user/path_to_unpacked_folders/
GR_skig GR_skig
======= =======
...@@ -245,7 +247,7 @@ OR_sun ...@@ -245,7 +247,7 @@ OR_sun
Implements loading dataset: Implements loading dataset:
_`"SUN Database"`: http://sun.cs.princeton.edu/ _`"SUN Database"`: http://sundatabase.mit.edu/
Currently implemented loading "Scene Recognition Benchmark. SUN397". Planned to implement also "Object Detection Benchmark. SUN2012". Currently implemented loading "Scene Recognition Benchmark. SUN397". Planned to implement also "Object Detection Benchmark. SUN2012".
......
...@@ -66,10 +66,12 @@ public: ...@@ -66,10 +66,12 @@ public:
std::vector< Ptr<Object> >& getTrain() { return train; } std::vector< Ptr<Object> >& getTrain() { return train; }
std::vector< Ptr<Object> >& getTest() { return test; } std::vector< Ptr<Object> >& getTest() { return test; }
std::vector< Ptr<Object> >& getValidation() { return validation; }
protected: protected:
std::vector< Ptr<Object> > train; std::vector< Ptr<Object> > train;
std::vector< Ptr<Object> > test; std::vector< Ptr<Object> > test;
std::vector< Ptr<Object> > validation;
}; };
} }
......
...@@ -59,10 +59,15 @@ namespace datasetstools ...@@ -59,10 +59,15 @@ namespace datasetstools
// 0.0000e+00 2.8285e+03 6.1618e+02 // 0.0000e+00 2.8285e+03 6.1618e+02
// 0.0000e+00 0.0000e+00 1.0000e+00 // 0.0000e+00 0.0000e+00 1.0000e+00
struct cameraPos
{
std::vector<std::string> images;
};
struct IR_robotObj : public Object struct IR_robotObj : public Object
{ {
std::string name; std::string name;
std::vector<std::string> images; // TODO: implement more complex structure std::vector<cameraPos> pos;
}; };
class CV_EXPORTS IR_robot : public Dataset class CV_EXPORTS IR_robot : public Dataset
......
...@@ -54,10 +54,21 @@ namespace cv ...@@ -54,10 +54,21 @@ namespace cv
namespace datasetstools namespace datasetstools
{ {
struct cameraParam
{
Matx33d mat1;
double mat2[3];
Matx33d mat3;
double mat4[3];
int imageWidth, imageHeight;
};
struct MSM_epflObj : public Object struct MSM_epflObj : public Object
{ {
std::string imageName; std::string imageName;
std::vector<double> bounding, camera, p; // TODO: implement better structures Matx23d bounding;
Matx34d p;
cameraParam camera;
}; };
class CV_EXPORTS MSM_epfl : public Dataset class CV_EXPORTS MSM_epfl : public Dataset
......
...@@ -71,10 +71,11 @@ int main(int argc, char *argv[]) ...@@ -71,10 +71,11 @@ int main(int argc, char *argv[])
// *************** // ***************
// dataset contains information for each sample. // dataset contains information for each sample.
// For example, let output dataset size and first element. // For example, let output dataset size and first element.
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("validation size: %u\n", (unsigned int)dataset->getValidation().size());
GR_chalearnObj *example = static_cast<GR_chalearnObj *>(dataset->getTrain()[0].get()); GR_chalearnObj *example = static_cast<GR_chalearnObj *>(dataset->getTrain()[0].get());
printf("first dataset sample:\n%s\n", example->name.c_str()); printf("first dataset sample:\n%s\n", example->name.c_str());
printf("color video:\n%s\n", example->nameColor .c_str()); printf("color video:\n%s\n", example->nameColor.c_str());
printf("depth video:\n%s\n", example->nameDepth.c_str()); printf("depth video:\n%s\n", example->nameDepth.c_str());
printf("user video:\n%s\n", example->nameUser.c_str()); printf("user video:\n%s\n", example->nameUser.c_str());
printf("video:\nnumber of frames: %u\nfps: %u\nmaximum depth: %u\n", example->numFrames, example->fps, example->depth); printf("video:\nnumber of frames: %u\nfps: %u\nmaximum depth: %u\n", example->numFrames, example->fps, example->depth);
......
...@@ -72,11 +72,17 @@ int main(int argc, char *argv[]) ...@@ -72,11 +72,17 @@ int main(int argc, char *argv[])
// dataset contains object with name and its images. // dataset contains object with name and its images.
// For example, let output last element and dataset size. // For example, let output last element and dataset size.
IR_robotObj *example = static_cast<IR_robotObj *>(dataset->getTrain().back().get()); IR_robotObj *example = static_cast<IR_robotObj *>(dataset->getTrain().back().get());
printf("last dataset object:\n%s\n", example->name.c_str()); printf("last dataset object:\n");
printf("name: %s\n", example->name.c_str());
printf("number postitions: %u\n", (unsigned int)example->pos.size());
string currPath(path + example->name + "/"); string currPath(path + example->name + "/");
for (vector<string>::iterator it=example->images.begin(); it!=example->images.end(); ++it)
for (vector<cameraPos>::iterator itP=example->pos.begin(); itP!=example->pos.end(); ++itP)
{ {
printf("%s\n", (currPath+(*it)).c_str()); for (vector<string>::iterator it=itP->images.begin(); it!=itP->images.end(); ++it)
{
printf("%s\n", (currPath+(*it)).c_str());
}
} }
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
......
...@@ -75,26 +75,60 @@ int main(int argc, char *argv[]) ...@@ -75,26 +75,60 @@ int main(int argc, char *argv[])
MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset->getTrain()[0].get()); MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset->getTrain()[0].get());
printf("first image:\nname: %s\n", example->imageName.c_str()); printf("first image:\nname: %s\n", example->imageName.c_str());
printf("bounding:\n"); printf("\nbounding:\n");
for (vector<double>::iterator it=example->bounding.begin(); it!=example->bounding.end(); ++it) for (int i=0; i<2; ++i)
{ {
printf("%f ", *it); for (int j=0; j<3; ++j)
{
printf("%f ", example->bounding(i, j));
}
printf("\n");
} }
printf("\n");
printf("camera:\n"); printf("\ncamera:\n");
for (vector<double>::iterator it=example->camera.begin(); it!=example->camera.end(); ++it) for (int i=0; i<3; ++i)
{ {
printf("%f ", *it); for (int j=0; j<3; ++j)
{
printf("%f ", example->camera.mat1(i, j));
}
printf("\n");
} }
printf("\n"); printf("\n");
printf("P:\n"); for (int i=0; i<3; ++i)
for (vector<double>::iterator it=example->p.begin(); it!=example->p.end(); ++it) {
printf("%f ", example->camera.mat2[i]);
}
printf("\n\n");
for (int i=0; i<3; ++i)
{ {
printf("%f ", *it); for (int j=0; j<3; ++j)
{
printf("%f ", example->camera.mat3(i, j));
}
printf("\n");
} }
printf("\n"); printf("\n");
for (int i=0; i<3; ++i)
{
printf("%f ", example->camera.mat4[i]);
}
printf("\n\n");
printf("image width: %u, height: %u\n", example->camera.imageWidth, example->camera.imageHeight);
printf("\nP:\n");
for (int i=0; i<3; ++i)
{
for (int j=0; j<4; ++j)
{
printf("%f ", example->p(i, j));
}
printf("\n");
}
return 0; return 0;
} }
...@@ -86,7 +86,7 @@ int main(int argc, char *argv[]) ...@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
} }
printf("file name: %s\n", (imagePath + example->name).c_str()); printf("file name: %s\n", (imagePath + example->name).c_str());
printf("transformation matrix:\n"); printf("\ntransformation matrix:\n");
for (unsigned int i=0; i<4; ++i) for (unsigned int i=0; i<4; ++i)
{ {
for (unsigned int j=0; j<4; ++j) for (unsigned int j=0; j<4; ++j)
......
...@@ -85,15 +85,20 @@ int main(int argc, char *argv[]) ...@@ -85,15 +85,20 @@ int main(int argc, char *argv[])
vector< Ptr<Object> > &currTrain = dataset.back()->getTrain(); vector< Ptr<Object> > &currTrain = dataset.back()->getTrain();
vector< Ptr<Object> > &currTest = dataset.back()->getTest(); vector< Ptr<Object> > &currTest = dataset.back()->getTest();
vector< Ptr<Object> > &currValidation = dataset.back()->getValidation();
printf("train size: %u\n", (unsigned int)currTrain.size()); printf("train size: %u\n", (unsigned int)currTrain.size());
printf("test size: %u\n", (unsigned int)currTest.size()); printf("test size: %u\n", (unsigned int)currTest.size());
printf("validation size: %u\n", (unsigned int)currValidation.size());
TR_charsObj *example1 = static_cast<TR_charsObj *>(currTrain[0].get()); TR_charsObj *exampleTrain = static_cast<TR_charsObj *>(currTrain[0].get());
TR_charsObj *example2 = static_cast<TR_charsObj *>(currTest[0].get()); TR_charsObj *exampleTest = static_cast<TR_charsObj *>(currTest[0].get());
printf("first train element:\nname: %s\n", example1->imgName.c_str()); TR_charsObj *exampleValidation = static_cast<TR_charsObj *>(currValidation[0].get());
printf("label: %u\n", example1->label); printf("first train element:\nname: %s\n", exampleTrain->imgName.c_str());
printf("first test element:\nname: %s\n", example2->imgName.c_str()); printf("label: %u\n", exampleTrain->label);
printf("label: %u\n", example2->label); printf("first test element:\nname: %s\n", exampleTest->imgName.c_str());
printf("label: %u\n", exampleTest->label);
printf("first validation element:\nname: %s\n", exampleValidation->imgName.c_str());
printf("label: %u\n", exampleValidation->label);
return 0; return 0;
} }
...@@ -60,6 +60,8 @@ public: ...@@ -60,6 +60,8 @@ public:
private: private:
void loadDataset(const std::string &path); void loadDataset(const std::string &path);
void loadDatasetPart(const std::string &path, std::vector< Ptr<Object> > &dataset_, bool loadLabels);
}; };
/*GR_chalearnImp::GR_chalearnImp(const string &path) /*GR_chalearnImp::GR_chalearnImp(const string &path)
...@@ -77,7 +79,7 @@ void GR_chalearnImp::load(const string &path, int number) ...@@ -77,7 +79,7 @@ void GR_chalearnImp::load(const string &path, int number)
loadDataset(path); loadDataset(path);
} }
void GR_chalearnImp::loadDataset(const string &path) void GR_chalearnImp::loadDatasetPart(const string &path, vector< Ptr<Object> > &dataset_, bool loadLabels)
{ {
vector<string> fileNames; vector<string> fileNames;
getDirList(path, fileNames); getDirList(path, fileNames);
...@@ -101,19 +103,22 @@ void GR_chalearnImp::loadDataset(const string &path) ...@@ -101,19 +103,22 @@ void GR_chalearnImp::loadDataset(const string &path)
curr->depth = atoi(elems[2].c_str()); curr->depth = atoi(elems[2].c_str());
// loading ground truth // loading ground truth
string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv"); if (loadLabels)
ifstream infileGroundTruth(fileGroundTruth.c_str());
while (getline(infileGroundTruth, line))
{ {
vector<string> elems2; string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv");
split(line, elems2, ','); ifstream infileGroundTruth(fileGroundTruth.c_str());
while (getline(infileGroundTruth, line))
{
vector<string> elems2;
split(line, elems2, ',');
groundTruth currGroundTruth; groundTruth currGroundTruth;
currGroundTruth.gestureID = atoi(elems2[0].c_str()); currGroundTruth.gestureID = atoi(elems2[0].c_str());
currGroundTruth.initialFrame = atoi(elems2[1].c_str()); currGroundTruth.initialFrame = atoi(elems2[1].c_str());
currGroundTruth.lastFrame = atoi(elems2[2].c_str()); currGroundTruth.lastFrame = atoi(elems2[2].c_str());
curr->groundTruths.push_back(currGroundTruth); curr->groundTruths.push_back(currGroundTruth);
}
} }
// loading skeleton // loading skeleton
...@@ -142,10 +147,20 @@ void GR_chalearnImp::loadDataset(const string &path) ...@@ -142,10 +147,20 @@ void GR_chalearnImp::loadDataset(const string &path)
curr->skeletons.push_back(currSkeleton); curr->skeletons.push_back(currSkeleton);
} }
train.push_back(curr); dataset_.push_back(curr);
} }
} }
void GR_chalearnImp::loadDataset(const string &path)
{
string pathTrain(path + "Train/");
loadDatasetPart(pathTrain, train, true);
// freely available validation set doesn't have labels
string pathValidation(path + "Validation/");
loadDatasetPart(pathValidation, validation, false);
}
Ptr<GR_chalearn> GR_chalearn::create() Ptr<GR_chalearn> GR_chalearn::create()
{ {
return Ptr<GR_chalearnImp>(new GR_chalearnImp); return Ptr<GR_chalearnImp>(new GR_chalearnImp);
......
...@@ -100,18 +100,28 @@ void GR_skigImp::loadDataset(const string &path) ...@@ -100,18 +100,28 @@ void GR_skigImp::loadDataset(const string &path)
curr->dep[0] = 'K'; curr->dep[0] = 'K';
curr->dep = pathDatasetDep + curr->dep; curr->dep = pathDatasetDep + curr->dep;
size_t pos = file.find("person_"); // TODO: check ::npos size_t posPerson = file.find("person_");
curr->person = (unsigned char)atoi( file.substr(pos+strlen("person_"), 1).c_str() ); size_t posBackground = file.find("backgroud_");
pos = file.find("backgroud_"); size_t posIllumination = file.find("illumination_");
curr->background = (backgroundType)atoi( file.substr(pos+strlen("backgroud_"), 1).c_str() ); size_t posPose = file.find("pose_");
pos = file.find("illumination_"); size_t posType = file.find("actionType_");
curr->illumination = (illuminationType)atoi( file.substr(pos+strlen("illumination_"), 1).c_str() ); if (string::npos != posPerson &&
pos = file.find("pose_"); string::npos != posBackground &&
curr->pose = (poseType)atoi( file.substr(pos+strlen("pose_"), 1).c_str() ); string::npos != posIllumination &&
pos = file.find("actionType_"); string::npos != posPose &&
curr->type = (actionType)atoi( file.substr(pos+strlen("actionType_"), 2).c_str() ); string::npos != posType)
{
train.push_back(curr); curr->person = (unsigned char)atoi( file.substr(posPerson + strlen("person_"), 1).c_str() );
curr->background = (backgroundType)atoi( file.substr(posBackground + strlen("backgroud_"), 1).c_str() );
curr->illumination = (illuminationType)atoi( file.substr(posIllumination + strlen("illumination_"), 1).c_str() );
curr->pose = (poseType)atoi( file.substr(posPose + strlen("pose_"), 1).c_str() );
curr->type = (actionType)atoi( file.substr(posType + strlen("actionType_"), 2).c_str() );
train.push_back(curr);
} else
{
printf("incorrect file name: %s", file.c_str());
}
} }
} }
} }
......
...@@ -89,9 +89,20 @@ void IR_robotImp::loadDataset(const string &path) ...@@ -89,9 +89,20 @@ void IR_robotImp::loadDataset(const string &path)
string pathScene(path + curr->name + "/"); string pathScene(path + curr->name + "/");
vector<string> sceneNames; vector<string> sceneNames;
getDirList(pathScene, sceneNames); getDirList(pathScene, sceneNames);
int currImageNum = 0;
for (vector<string>::iterator itScene=sceneNames.begin(); itScene!=sceneNames.end(); ++itScene) for (vector<string>::iterator itScene=sceneNames.begin(); itScene!=sceneNames.end(); ++itScene)
{ {
curr->images.push_back(*itScene); string &fileName = *itScene;
int imageNum = atoi( fileName.substr(3, 3).c_str() );
int pos = atoi( fileName.substr(6, 2).c_str() );
if (imageNum != currImageNum)
{
curr->pos.push_back(cameraPos());
currImageNum = imageNum;
}
curr->pos.back().images.push_back(fileName);
} }
train.push_back(curr); train.push_back(curr);
......
...@@ -60,20 +60,8 @@ public: ...@@ -60,20 +60,8 @@ public:
private: private:
void loadDataset(const std::string &path); void loadDataset(const std::string &path);
void readFileDouble(const std::string &fileName, std::vector<double> &out);
}; };
void MSM_epflImp::readFileDouble(const string &fileName, vector<double> &out)
{
ifstream infile(fileName.c_str());
double val;
while (infile >> val)
{
out.push_back(val);
}
}
/*MSM_epflImp::MSM_epflImp(const string &path) /*MSM_epflImp::MSM_epflImp(const string &path)
{ {
loadDataset(path); loadDataset(path);
...@@ -103,9 +91,58 @@ void MSM_epflImp::loadDataset(const string &path) ...@@ -103,9 +91,58 @@ void MSM_epflImp::loadDataset(const string &path)
Ptr<MSM_epflObj> curr(new MSM_epflObj); Ptr<MSM_epflObj> curr(new MSM_epflObj);
curr->imageName = *it; curr->imageName = *it;
readFileDouble(string(pathBounding + curr->imageName + ".bounding"), curr->bounding); // load boundary
readFileDouble(string(pathCamera + curr->imageName + ".camera"), curr->camera); string fileBounding(pathBounding + curr->imageName + ".bounding");
readFileDouble(string(pathP + curr->imageName + ".P"), curr->p); ifstream infile(fileBounding.c_str());
for (int k=0; k<2; ++k)
{
for (int j=0; j<3; ++j)
{
infile >> curr->bounding(k, j);
}
}
// load camera parameters
string fileCamera(pathCamera + curr->imageName + ".camera");
ifstream infileCamera(fileCamera.c_str());
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j)
{
infileCamera >> curr->camera.mat1(i, j);
}
}
for (int i=0; i<3; ++i)
{
infileCamera >> curr->camera.mat2[i];
}
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j)
{
infileCamera >> curr->camera.mat3(i, j);
}
}
for (int i=0; i<3; ++i)
{
infileCamera >> curr->camera.mat4[i];
}
infileCamera >> curr->camera.imageWidth >> curr->camera.imageHeight;
// load P
string fileP(pathP + curr->imageName + ".P");
ifstream infileP(fileP.c_str());
for (int k=0; k<3; ++k)
{
for (int j=0; j<4; ++j)
{
infileP >> curr->p(k, j);
}
}
train.push_back(curr); train.push_back(curr);
} }
......
...@@ -81,8 +81,34 @@ void SLAM_tumindoorImp::load(const string &path, int number) ...@@ -81,8 +81,34 @@ void SLAM_tumindoorImp::load(const string &path, int number)
void SLAM_tumindoorImp::loadDataset(const string &path) void SLAM_tumindoorImp::loadDataset(const string &path)
{ {
string infoPath(path + "info/2011-12-17_15.02.56-info.csv"); // TODO string infoPath(path + "info/");
ifstream infile(infoPath.c_str());
// get info map name, .csv should be only one such file in folder
string csvName;
vector<string> infoNames;
getDirList(infoPath, infoNames);
for (vector<string>::iterator it=infoNames.begin(); it!=infoNames.end(); ++it)
{
string &name = *it;
if (name.length()>3 && name.substr( name.length()-4, 4 )==".csv")
{
if (csvName.length()==0)
{
csvName = name;
} else
{
printf("more than one .csv file in info folder\n");
return;
}
}
}
if (csvName.length()==0)
{
printf("didn't find .csv file in info folder\n");
return;
}
ifstream infile((infoPath + csvName).c_str());
string line; string line;
while (getline(infile, line)) while (getline(infile, line))
{ {
......
...@@ -53,15 +53,19 @@ class CV_EXPORTS TR_charsImp : public TR_chars ...@@ -53,15 +53,19 @@ class CV_EXPORTS TR_charsImp : public TR_chars
{ {
public: public:
TR_charsImp() {} TR_charsImp() {}
//TR_charsImp(const std::string &path, int number = 0); //TR_charsImp(const string &path, int number = 0);
virtual ~TR_charsImp() {} virtual ~TR_charsImp() {}
virtual void load(const std::string &path, int number = 0); virtual void load(const string &path, int number = 0);
private: private:
void loadDataset(const std::string &path, int number = 0); void loadDataset(const string &path, int number = 0);
void parseLine(const std::string &line, std::vector<int> &currSet, int number); void parseLine(const string &line, vector<int> &currSet, int number);
inline void convert(vector<int> &from, vector< Ptr<Object> > &to, vector<int> &allLabels, vector<string> &allNames);
inline void parseSet(const string &line, const string &pattern, bool &flag, vector<int> &set, int number);
}; };
void TR_charsImp::parseLine(const string &line, vector<int> &currSet, int number) void TR_charsImp::parseLine(const string &line, vector<int> &currSet, int number)
...@@ -80,6 +84,38 @@ void TR_charsImp::parseLine(const string &line, vector<int> &currSet, int number ...@@ -80,6 +84,38 @@ void TR_charsImp::parseLine(const string &line, vector<int> &currSet, int number
} }
} }
inline void TR_charsImp::convert(vector<int> &from, std::vector< Ptr<Object> > &to, vector<int> &allLabels, vector<string> &allNames)
{
for (vector<int>::iterator it=from.begin(); it!=from.end(); ++it)
{
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size())
{
printf("incorrect index: %u\n", *it);
continue;
}
Ptr<TR_charsObj> curr(new TR_charsObj);
curr->imgName = allNames[*it];
curr->label = allLabels[*it];
to.push_back(curr);
}
}
inline void TR_charsImp::parseSet(const string &line, const string &pattern, bool &flag, vector<int> &set, int number)
{
size_t pos = line.find(pattern);
if (string::npos != pos)
{
flag = true;
string s(line.substr(pos + pattern.length()));
parseLine(s, set, number);
} else
if (flag)
{
parseLine(line, set, number);
}
}
/*TR_charsImp::TR_charsImp(const string &path, int number) /*TR_charsImp::TR_charsImp(const string &path, int number)
{ {
loadDataset(path, number); loadDataset(path, number);
...@@ -92,21 +128,22 @@ void TR_charsImp::load(const string &path, int number) ...@@ -92,21 +128,22 @@ void TR_charsImp::load(const string &path, int number)
void TR_charsImp::loadDataset(const string &path, int number) void TR_charsImp::loadDataset(const string &path, int number)
{ {
vector<int> allLabels, trainSet, testSet; vector<int> allLabels, trainSet, testSet, validationSet;
vector<string> allNames; vector<string> allNames;
ifstream infile((path + "list_English_Img.m").c_str()); ifstream infile((path + "list_English_Img.m").c_str());
string line; string line;
bool labels = false, names = false, isTrain = false, isTest = false; bool labels = false, names = false, isTrain = false, isTest = false, isValidation = false;
while (getline(infile, line)) while (getline(infile, line))
{ {
size_t pos = line.find("];"); size_t pos = line.find("];");
if (string::npos!=pos) if (string::npos != pos)
{ {
labels = false; labels = false;
names = false; names = false;
isTrain = false; isTrain = false;
isTest = false; isTest = false;
isValidation = false;
} }
string slabels("list.ALLlabels = ["); string slabels("list.ALLlabels = [");
...@@ -124,7 +161,7 @@ void TR_charsImp::loadDataset(const string &path, int number) ...@@ -124,7 +161,7 @@ void TR_charsImp::loadDataset(const string &path, int number)
string snames("list.ALLnames = ["); string snames("list.ALLnames = [");
pos = line.find(snames); pos = line.find(snames);
if (string::npos!=pos) if (string::npos != pos)
{ {
names = true; names = true;
size_t start = pos+snames.length(); size_t start = pos+snames.length();
...@@ -137,66 +174,24 @@ void TR_charsImp::loadDataset(const string &path, int number) ...@@ -137,66 +174,24 @@ void TR_charsImp::loadDataset(const string &path, int number)
allNames.push_back(s); allNames.push_back(s);
} }
string strain("list.TRNind = ["); string trainStr("list.TRNind = [");
pos = line.find(strain); parseSet(line, trainStr, isTrain, trainSet, number);
if (string::npos!=pos)
{
isTrain = true;
string s(line.substr(pos+strain.length()));
parseLine(s, trainSet, number);
} else
if (isTrain)
{
parseLine(line, trainSet, number);
}
string stest("list.TSTind = ["); string testStr("list.TSTind = [");
pos = line.find(stest); parseSet(line, testStr, isTest, testSet, number);
if (string::npos!=pos)
{ string validationStr("list.VALind = [");
isTest = true; parseSet(line, validationStr, isValidation, validationSet, number);
string s(line.substr(pos+stest.length()));
parseLine(s, testSet, number);
} else
if (isTest)
{
parseLine(line, testSet, number);
}
/*"list.classlabels = [" /*"list.classlabels = ["
"list.classnames = [" "list.classnames = ["
"list.NUMclasses = 62;" "list.NUMclasses = 62;"
"list.VALind = [" // TODO: load validation
"list.TXNind = ["*/ "list.TXNind = ["*/
} }
for (vector<int>::iterator it=trainSet.begin(); it!=trainSet.end(); ++it) convert(trainSet, train, allLabels, allNames);
{ convert(testSet, test, allLabels, allNames);
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size()) convert(validationSet, validation, allLabels, allNames);
{
printf("incorrect train index: %u\n", *it);
continue;
}
Ptr<TR_charsObj> curr(new TR_charsObj);
curr->imgName = allNames[*it];
curr->label = allLabels[*it];
train.push_back(curr);
}
for (vector<int>::iterator it=testSet.begin(); it!=testSet.end(); ++it)
{
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size())
{
printf("incorrect test index: %u\n", *it);
continue;
}
Ptr<TR_charsObj> curr(new TR_charsObj);
curr->imgName = allNames[*it];
curr->label = allLabels[*it];
test.push_back(curr);
}
} }
Ptr<TR_chars> TR_chars::create() Ptr<TR_chars> TR_chars::create()
......
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