Commit 47131fd1 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #84 from avdmitry/datasetstools2

datasets loading module: continue
parents bc5d9c51 ee12bc12
...@@ -6,8 +6,6 @@ datasetstools. Tools for working with different datasets. ...@@ -6,8 +6,6 @@ datasetstools. Tools for working with different datasets.
The datasetstools module includes classes for working with different datasets. The datasetstools module includes classes for working with different datasets.
First version of this module was implemented for **Fall2014 OpenCV Challenge**.
Action Recognition Action Recognition
------------------ ------------------
...@@ -50,13 +48,13 @@ FR_lfw ...@@ -50,13 +48,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/
...@@ -75,9 +73,11 @@ _`"ChaLearn Looking at People"`: http://gesture.chalearn.org/ ...@@ -75,9 +73,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
======= =======
...@@ -239,13 +239,29 @@ Currently implemented loading full list with urls. Planned to implement dataset ...@@ -239,13 +239,29 @@ Currently implemented loading full list with urls. Planned to implement dataset
3. To load data run: ./opencv/build/bin/example_datasetstools_or_imagenet -p=/home/user/path_to_unpacked_file/ 3. To load data run: ./opencv/build/bin/example_datasetstools_or_imagenet -p=/home/user/path_to_unpacked_file/
OR_mnist
===========
.. ocv:class:: OR_mnist
Implements loading dataset:
_`"MNIST"`: http://yann.lecun.com/exdb/mnist/
.. note:: Usage
1. From link above download dataset files: t10k-images-idx3-ubyte.gz, t10k-labels-idx1-ubyte.gz, train-images-idx3-ubyte.gz, train-labels-idx1-ubyte.gz.
2. Unpack them.
3. To load data run: ./opencv/build/bin/example_datasetstools_or_mnist -p=/home/user/path_to_unpacked_files/
OR_sun OR_sun
====== ======
.. ocv:class:: OR_sun .. ocv:class:: 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".
......
...@@ -63,16 +63,9 @@ struct AR_hmdbObj : public Object ...@@ -63,16 +63,9 @@ struct AR_hmdbObj : public Object
class CV_EXPORTS AR_hmdb : public Dataset class CV_EXPORTS AR_hmdb : public Dataset
{ {
public: public:
AR_hmdb() {} virtual void load(const std::string &path) = 0;
AR_hmdb(const std::string &path, int number = 0);
virtual ~AR_hmdb() {}
virtual void load(const std::string &path, int number = 0); static Ptr<AR_hmdb> create();
private:
void loadDataset(const std::string &path, int number = 0);
void loadAction(const std::string &fileName, std::vector<std::string> &train_, std::vector<std::string> &test_);
}; };
} }
......
...@@ -63,16 +63,9 @@ struct AR_sportsObj : public Object ...@@ -63,16 +63,9 @@ struct AR_sportsObj : public Object
class CV_EXPORTS AR_sports : public Dataset class CV_EXPORTS AR_sports : public Dataset
{ {
public: public:
AR_sports() {} virtual void load(const std::string &path) = 0;
AR_sports(const std::string &path);
virtual ~AR_sports() {}
virtual void load(const std::string &path, int number = 0); static Ptr<AR_sports> create();
private:
void loadDataset(const std::string &path);
void loadDatasetPart(const std::string &fileName, std::vector< Ptr<Object> > &dataset_);
}; };
} }
......
...@@ -62,10 +62,21 @@ public: ...@@ -62,10 +62,21 @@ public:
Dataset() {} Dataset() {}
virtual ~Dataset() {} virtual ~Dataset() {}
virtual void load(const std::string &path, int number = 0) = 0; virtual void load(const std::string &path) = 0;
std::vector< Ptr<Object> > train; std::vector< Ptr<Object> >& getTrain(int splitNum = 0);
std::vector< Ptr<Object> > test; std::vector< Ptr<Object> >& getTest(int splitNum = 0);
std::vector< Ptr<Object> >& getValidation(int splitNum = 0);
int getNumSplits() const;
protected:
std::vector< std::vector< Ptr<Object> > > train;
std::vector< std::vector< Ptr<Object> > > test;
std::vector< std::vector< Ptr<Object> > > validation;
private:
std::vector< Ptr<Object> > empty;
}; };
} }
......
...@@ -56,21 +56,16 @@ namespace datasetstools ...@@ -56,21 +56,16 @@ 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
{ {
public: public:
FR_lfw() {} virtual void load(const std::string &path) = 0;
FR_lfw(const std::string &path);
virtual ~FR_lfw() {}
virtual void load(const std::string &path, int number = 0); static Ptr<FR_lfw> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -80,14 +80,9 @@ struct GR_chalearnObj : public Object ...@@ -80,14 +80,9 @@ struct GR_chalearnObj : public Object
class CV_EXPORTS GR_chalearn : public Dataset class CV_EXPORTS GR_chalearn : public Dataset
{ {
public: public:
GR_chalearn() {} virtual void load(const std::string &path) = 0;
GR_chalearn(const std::string &path);
virtual ~GR_chalearn() {}
virtual void load(const std::string &path, int number = 0); static Ptr<GR_chalearn> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -102,14 +102,9 @@ struct GR_skigObj : public Object ...@@ -102,14 +102,9 @@ struct GR_skigObj : public Object
class CV_EXPORTS GR_skig : public Dataset class CV_EXPORTS GR_skig : public Dataset
{ {
public: public:
GR_skig() {} virtual void load(const std::string &path) = 0;
GR_skig(const std::string &path);
virtual ~GR_skig() {}
virtual void load(const std::string &path, int number = 0); static Ptr<GR_skig> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -62,14 +62,9 @@ struct HPE_parseObj : public Object ...@@ -62,14 +62,9 @@ struct HPE_parseObj : public Object
class CV_EXPORTS HPE_parse : public Dataset class CV_EXPORTS HPE_parse : public Dataset
{ {
public: public:
HPE_parse() {} virtual void load(const std::string &path) = 0;
HPE_parse(const std::string &path);
virtual ~HPE_parse() {}
virtual void load(const std::string &path, int number = 0); static Ptr<HPE_parse> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -64,14 +64,9 @@ struct IR_affineObj : public Object ...@@ -64,14 +64,9 @@ struct IR_affineObj : public Object
class CV_EXPORTS IR_affine : public Dataset class CV_EXPORTS IR_affine : public Dataset
{ {
public: public:
IR_affine() {} virtual void load(const std::string &path) = 0;
IR_affine(const std::string &path);
virtual ~IR_affine() {}
virtual void load(const std::string &path, int number = 0); static Ptr<IR_affine> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -59,23 +59,23 @@ namespace datasetstools ...@@ -59,23 +59,23 @@ 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
{ {
public: public:
IR_robot() {} virtual void load(const std::string &path) = 0;
IR_robot(const std::string &path);
virtual ~IR_robot() {}
virtual void load(const std::string &path, int number = 0);
private: static Ptr<IR_robot> create();
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -62,16 +62,9 @@ struct IS_bsdsObj : public Object ...@@ -62,16 +62,9 @@ struct IS_bsdsObj : public Object
class CV_EXPORTS IS_bsds : public Dataset class CV_EXPORTS IS_bsds : public Dataset
{ {
public: public:
IS_bsds() {} virtual void load(const std::string &path) = 0;
IS_bsds(const std::string &path);
virtual ~IS_bsds() {}
virtual void load(const std::string &path, int number = 0); static Ptr<IS_bsds> create();
private:
void loadDataset(const std::string &path);
void loadDatasetPart(const std::string &fileName, std::vector< Ptr<Object> > &dataset_);
}; };
} }
......
...@@ -65,14 +65,9 @@ struct IS_weizmannObj : public Object ...@@ -65,14 +65,9 @@ struct IS_weizmannObj : public Object
class CV_EXPORTS IS_weizmann : public Dataset class CV_EXPORTS IS_weizmann : public Dataset
{ {
public: public:
IS_weizmann() {} virtual void load(const std::string &path) = 0;
IS_weizmann(const std::string &path);
virtual ~IS_weizmann() {}
virtual void load(const std::string &path, int number = 0); static Ptr<IS_weizmann> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -54,25 +54,29 @@ namespace cv ...@@ -54,25 +54,29 @@ 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
{ {
public: public:
MSM_epfl() {} virtual void load(const std::string &path) = 0;
MSM_epfl(const std::string &path);
virtual ~MSM_epfl() {}
virtual void load(const std::string &path, int number = 0);
private:
void loadDataset(const std::string &path);
void readFileDouble(const std::string &fileName, std::vector<double> &out); static Ptr<MSM_epfl> create();
}; };
} }
......
...@@ -57,22 +57,17 @@ namespace datasetstools ...@@ -57,22 +57,17 @@ namespace datasetstools
struct MSM_middleburyObj : public Object struct MSM_middleburyObj : public Object
{ {
std::string imageName; std::string imageName;
double k[3][3]; Matx33d k;
double r[3][3]; Matx33d r;
double t[3]; double t[3];
}; };
class CV_EXPORTS MSM_middlebury : public Dataset class CV_EXPORTS MSM_middlebury : public Dataset
{ {
public: public:
MSM_middlebury() {} virtual void load(const std::string &path) = 0;
MSM_middlebury(const std::string &path);
virtual ~MSM_middlebury() {}
virtual void load(const std::string &path, int number = 0); static Ptr<MSM_middlebury> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <set>
#include "opencv2/datasetstools/dataset.hpp" #include "opencv2/datasetstools/dataset.hpp"
...@@ -65,16 +64,9 @@ struct OR_imagenetObj : public Object ...@@ -65,16 +64,9 @@ struct OR_imagenetObj : public Object
class CV_EXPORTS OR_imagenet : public Dataset class CV_EXPORTS OR_imagenet : public Dataset
{ {
public: public:
OR_imagenet() {} virtual void load(const std::string &path) = 0;
OR_imagenet(const std::string &path);
virtual ~OR_imagenet() {}
virtual void load(const std::string &path, int number = 0); static Ptr<OR_imagenet> create();
std::set<std::string> wnids;
private:
void loadDataset(const std::string &path);
}; };
} }
......
/*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_DATASETSTOOLS_OR_MNIST_HPP
#define OPENCV_DATASETSTOOLS_OR_MNIST_HPP
#include <string>
#include <vector>
#include "opencv2/datasetstools/dataset.hpp"
#include <opencv2/core.hpp>
namespace cv
{
namespace datasetstools
{
struct OR_mnistObj : public Object
{
char label; // 0..9
Mat image; // [28][28]
};
class CV_EXPORTS OR_mnist : public Dataset
{
public:
virtual void load(const std::string &path) = 0;
static Ptr<OR_mnist> create();
};
}
}
#endif
...@@ -63,14 +63,9 @@ struct OR_sunObj : public Object ...@@ -63,14 +63,9 @@ struct OR_sunObj : public Object
class CV_EXPORTS OR_sun : public Dataset class CV_EXPORTS OR_sun : public Dataset
{ {
public: public:
OR_sun() {} virtual void load(const std::string &path) = 0;
OR_sun(const std::string &path);
virtual ~OR_sun() {}
virtual void load(const std::string &path, int number = 0); static Ptr<OR_sun> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -71,14 +71,9 @@ struct SLAM_kittiObj : public Object ...@@ -71,14 +71,9 @@ struct SLAM_kittiObj : public Object
class CV_EXPORTS SLAM_kitti : public Dataset class CV_EXPORTS SLAM_kitti : public Dataset
{ {
public: public:
SLAM_kitti() {} virtual void load(const std::string &path) = 0;
SLAM_kitti(const std::string &path);
virtual ~SLAM_kitti() {}
virtual void load(const std::string &path, int number = 0); static Ptr<SLAM_kitti> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -64,21 +64,16 @@ enum imageType ...@@ -64,21 +64,16 @@ enum imageType
struct SLAM_tumindoorObj : public Object struct SLAM_tumindoorObj : public Object
{ {
std::string name; std::string name;
double transformMat[4][4]; Matx44d transformMat;
imageType type; imageType type;
}; };
class CV_EXPORTS SLAM_tumindoor : public Dataset class CV_EXPORTS SLAM_tumindoor : public Dataset
{ {
public: public:
SLAM_tumindoor() {} virtual void load(const std::string &path) = 0;
SLAM_tumindoor(const std::string &path);
virtual ~SLAM_tumindoor() {}
virtual void load(const std::string &path, int number = 0); static Ptr<SLAM_tumindoor> create();
private:
void loadDataset(const std::string &path);
}; };
} }
......
...@@ -63,16 +63,9 @@ struct TR_charsObj : public Object ...@@ -63,16 +63,9 @@ struct TR_charsObj : public Object
class CV_EXPORTS TR_chars : public Dataset class CV_EXPORTS TR_chars : public Dataset
{ {
public: public:
TR_chars() {} virtual void load(const std::string &path) = 0;
TR_chars(const std::string &path, int number = 0);
virtual ~TR_chars() {}
virtual void load(const std::string &path, int number = 0); static Ptr<TR_chars> create();
private:
void loadDataset(const std::string &path, int number = 0);
void parseLine(const std::string &line, std::vector<int> &currSet, int number);
}; };
} }
......
...@@ -70,16 +70,9 @@ struct TR_svtObj : public Object ...@@ -70,16 +70,9 @@ struct TR_svtObj : public Object
class CV_EXPORTS TR_svt : public Dataset class CV_EXPORTS TR_svt : public Dataset
{ {
public: public:
TR_svt() {} virtual void load(const std::string &path) = 0;
TR_svt(const std::string &path);
virtual ~TR_svt() {}
virtual void load(const std::string &path, int number = 0); static Ptr<TR_svt> create();
private:
void loadDataset(const std::string &path);
void xmlParse(const std::string &set, std::vector< Ptr<Object> > &out);
}; };
} }
......
...@@ -65,17 +65,17 @@ int main(int argc, char *argv[]) ...@@ -65,17 +65,17 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
AR_hmdb dataset[3]; Ptr<AR_hmdb> dataset = AR_hmdb::create();
for (int i=0; i<3; ++i) dataset->load(path);
{
dataset[i].load(path, i);
}
// *************** // ***************
// 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.
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset[1].train[0].get()); int numSplits = dataset->getNumSplits();
printf("splits number: %u\n", numSplits);
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;
printf("size: %u\n", (unsigned int)videoNames.size()); printf("size: %u\n", (unsigned int)videoNames.size());
......
...@@ -66,16 +66,17 @@ int main(int argc, char *argv[]) ...@@ -66,16 +66,17 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
AR_sports dataset(path); Ptr<AR_sports> dataset = AR_sports::create();
dataset->load(path);
// *************** // ***************
// dataset. train & test contains for each video url in dataset all it's labels. // dataset. train & test contains for each video url in dataset all it's labels.
// For example, let output the first element in test dataset and it's labels. // For example, let output the first element in test dataset and it's labels.
// And sizes of both datasets. // And sizes of both datasets.
printf("train size: %u\n", (unsigned int)dataset.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("test size: %u\n", (unsigned int)dataset.test.size()); printf("test size: %u\n", (unsigned int)dataset->getTest().size());
AR_sportsObj *example = static_cast<AR_sportsObj *>(dataset.test[0].get()); AR_sportsObj *example = static_cast<AR_sportsObj *>(dataset->getTest()[0].get());
printf("url: %s\n", example->videoUrl.c_str()); printf("url: %s\n", example->videoUrl.c_str());
printf("labels: "); printf("labels: ");
vector<int> &labels = example->labels; vector<int> &labels = example->labels;
......
...@@ -65,19 +65,25 @@ int main(int argc, char *argv[]) ...@@ -65,19 +65,25 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
FR_lfw dataset(path); Ptr<FR_lfw> dataset = FR_lfw::create();
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.train.size()); int numSplits = dataset->getNumSplits();
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset.train[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;
} }
...@@ -65,15 +65,17 @@ int main(int argc, char *argv[]) ...@@ -65,15 +65,17 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
GR_chalearn dataset(path); Ptr<GR_chalearn> dataset = GR_chalearn::create();
dataset->load(path);
// *************** // ***************
// 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.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
GR_chalearnObj *example = static_cast<GR_chalearnObj *>(dataset.train[0].get()); printf("validation size: %u\n", (unsigned int)dataset->getValidation().size());
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);
......
...@@ -66,13 +66,14 @@ int main(int argc, char *argv[]) ...@@ -66,13 +66,14 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
GR_skig dataset(path); Ptr<GR_skig> dataset = GR_skig::create();
dataset->load(path);
// *************** // ***************
// dataset contains pair of rgb\dep images // dataset contains pair of rgb\dep images
// For example, let output train size and second element. // For example, let output train size and second element.
GR_skigObj *example = static_cast<GR_skigObj *>(dataset.train[1].get()); GR_skigObj *example = static_cast<GR_skigObj *>(dataset->getTrain()[1].get());
printf("train size: %u\n", (unsigned int)dataset.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("second train image:\nrgb: %s\ndep: %s\n", example->rgb.c_str(), example->dep.c_str()); printf("second train image:\nrgb: %s\ndep: %s\n", example->rgb.c_str(), example->dep.c_str());
printf("person: %u, backgroud: %u, illumination: %u, pose: %u, actionType: %u\n", printf("person: %u, backgroud: %u, illumination: %u, pose: %u, actionType: %u\n",
example->person, example->background, example->illumination, example->pose, example->type); example->person, example->background, example->illumination, example->pose, example->type);
......
...@@ -65,15 +65,16 @@ int main(int argc, char *argv[]) ...@@ -65,15 +65,16 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
HPE_parse dataset(path); Ptr<HPE_parse> dataset = HPE_parse::create();
dataset->load(path);
// *************** // ***************
// dataset. train & test contain appropriate images // dataset. train & test contain appropriate images
// For example, let output their sizes and first elements. // For example, let output their sizes and first elements.
printf("train size: %u\n", (unsigned int)dataset.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("test size: %u\n", (unsigned int)dataset.test.size()); printf("test size: %u\n", (unsigned int)dataset->getTest().size());
HPE_parseObj *example1 = static_cast<HPE_parseObj *>(dataset.train[0].get()); HPE_parseObj *example1 = static_cast<HPE_parseObj *>(dataset->getTrain()[0].get());
HPE_parseObj *example2 = static_cast<HPE_parseObj *>(dataset.test[0].get()); HPE_parseObj *example2 = static_cast<HPE_parseObj *>(dataset->getTest()[0].get());
printf("first train image: %s\n", example1->name.c_str()); printf("first train image: %s\n", example1->name.c_str());
printf("first test image: %s\n", example2->name.c_str()); printf("first test image: %s\n", example2->name.c_str());
......
...@@ -67,15 +67,16 @@ int main(int argc, char *argv[]) ...@@ -67,15 +67,16 @@ int main(int argc, char *argv[])
} }
// loading dataset // loading dataset
IR_affine dataset(path); Ptr<IR_affine> dataset = IR_affine::create();
dataset->load(path);
// *************** // ***************
// dataset contains for each image in dataset it's matrix. // dataset contains for each image in dataset it's matrix.
// For example, let output the last element in dataset and it's matrix. // For example, let output the last element in dataset and it's matrix.
// And dataset size. // And dataset size.
printf("size: %u\n", (unsigned int)dataset.train.size()); printf("size: %u\n", (unsigned int)dataset->getTrain().size());
IR_affineObj *example = static_cast<IR_affineObj *>(dataset.train.back().get()); IR_affineObj *example = static_cast<IR_affineObj *>(dataset->getTrain().back().get());
printf("image name: %s\n", example->imageName.c_str()); printf("image name: %s\n", example->imageName.c_str());
printf("matrix:\n"); printf("matrix:\n");
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
......
...@@ -65,19 +65,26 @@ int main(int argc, char *argv[]) ...@@ -65,19 +65,26 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
IR_robot dataset(path); Ptr<IR_robot> dataset = IR_robot::create();
dataset->load(path);
// *************** // ***************
// 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.train.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)
{
for (vector<string>::iterator it=itP->images.begin(); it!=itP->images.end(); ++it)
{ {
printf("%s\n", (currPath+(*it)).c_str()); printf("%s\n", (currPath+(*it)).c_str());
} }
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); }
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
return 0; return 0;
} }
...@@ -65,7 +65,8 @@ int main(int argc, char *argv[]) ...@@ -65,7 +65,8 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
IS_bsds dataset(path); Ptr<IS_bsds> dataset = IS_bsds::create();
dataset->load(path);
// TODO: read human/ folder for evaluation // TODO: read human/ folder for evaluation
...@@ -73,13 +74,13 @@ int main(int argc, char *argv[]) ...@@ -73,13 +74,13 @@ int main(int argc, char *argv[])
// dataset. train & test contain names of appropriate images. // dataset. train & test contain names of appropriate images.
// For example, let output full path & name for first train and test images. // For example, let output full path & name for first train and test images.
// And sets size. // And sets size.
printf("train size: %u\n", (unsigned int)dataset.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("test size: %u\n", (unsigned int)dataset.test.size()); printf("test size: %u\n", (unsigned int)dataset->getTest().size());
IS_bsdsObj *example1 = static_cast<IS_bsdsObj *>(dataset.train[0].get()); IS_bsdsObj *example1 = static_cast<IS_bsdsObj *>(dataset->getTrain()[0].get());
string fullPath(path + "images/train/" + example1->name + ".jpg"); string fullPath(path + "images/train/" + example1->name + ".jpg");
printf("first train image: %s\n", fullPath.c_str()); printf("first train image: %s\n", fullPath.c_str());
IS_bsdsObj *example2 = static_cast<IS_bsdsObj *>(dataset.test[0].get()); IS_bsdsObj *example2 = static_cast<IS_bsdsObj *>(dataset->getTest()[0].get());
fullPath = path + "images/test/" + example2->name + ".jpg"; fullPath = path + "images/test/" + example2->name + ".jpg";
printf("first test image: %s\n", fullPath.c_str()); printf("first test image: %s\n", fullPath.c_str());
......
...@@ -65,13 +65,14 @@ int main(int argc, char *argv[]) ...@@ -65,13 +65,14 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
IS_weizmann dataset(path); Ptr<IS_weizmann> dataset = IS_weizmann::create();
dataset->load(path);
// *************** // ***************
// dataset contains all information for each image. // dataset contains all information for each image.
// For example, let output dataset size and first object. // For example, let output dataset size and first object.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
IS_weizmannObj *example = static_cast<IS_weizmannObj *>(dataset.train[0].get()); IS_weizmannObj *example = static_cast<IS_weizmannObj *>(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("src bw: %s\nsrc color: %s\n", example->srcBw.c_str(), example->srcColor.c_str()); printf("src bw: %s\nsrc color: %s\n", example->srcBw.c_str(), example->srcColor.c_str());
......
...@@ -65,35 +65,70 @@ int main(int argc, char *argv[]) ...@@ -65,35 +65,70 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
MSM_epfl dataset(path); Ptr<MSM_epfl> dataset = MSM_epfl::create();
dataset->load(path);
// *************** // ***************
// dataset contains all information for each image. // dataset contains all information for each image.
// For example, let output dataset size and first object. // For example, let output dataset size and first object.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset.train[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)
{
for (int j=0; j<3; ++j)
{ {
printf("%f ", *it); 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 ", *it); printf("%f ", example->camera.mat2[i]);
}
printf("\n\n");
for (int i=0; i<3; ++i)
{
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;
} }
...@@ -65,20 +65,21 @@ int main(int argc, char *argv[]) ...@@ -65,20 +65,21 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
MSM_middlebury dataset(path); Ptr<MSM_middlebury> dataset = MSM_middlebury::create();
dataset->load(path);
// *************** // ***************
// dataset contains camera parameters for each image. // dataset contains camera parameters for each image.
// For example, let output number of elements and last element. // For example, let output number of elements and last element.
printf("images number: %u\n", (unsigned int)dataset.train.size()); printf("images number: %u\n", (unsigned int)dataset->getTrain().size());
MSM_middleburyObj *example = static_cast<MSM_middleburyObj *>(dataset.train.back().get()); MSM_middleburyObj *example = static_cast<MSM_middleburyObj *>(dataset->getTrain().back().get());
printf("last image name: %s\n", (path + example->imageName).c_str()); printf("last image name: %s\n", (path + example->imageName).c_str());
printf("K:\n"); printf("K:\n");
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
{ {
for (int j=0; j<3; ++j) for (int j=0; j<3; ++j)
{ {
printf("%f ", example->k[i][j]); printf("%f ", example->k(i, j));
} }
printf("\n"); printf("\n");
} }
...@@ -87,7 +88,7 @@ int main(int argc, char *argv[]) ...@@ -87,7 +88,7 @@ int main(int argc, char *argv[])
{ {
for (int j=0; j<3; ++j) for (int j=0; j<3; ++j)
{ {
printf("%f ", example->r[i][j]); printf("%f ", example->r(i, j));
} }
printf("\n"); printf("\n");
} }
......
...@@ -67,14 +67,14 @@ int main(int argc, char *argv[]) ...@@ -67,14 +67,14 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
OR_imagenet dataset(path); Ptr<OR_imagenet> dataset = OR_imagenet::create();
dataset->load(path);
// *************** // ***************
// dataset contains for each object its id & image url. // dataset contains for each object its id & image url.
// For example, let output dataset size and first object. // For example, let output dataset size and first object.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
printf("wnids number: %u\n", (unsigned int)dataset.wnids.size()); OR_imagenetObj *example = static_cast<OR_imagenetObj *>(dataset->getTrain()[0].get());
OR_imagenetObj *example = static_cast<OR_imagenetObj *>(dataset.train[0].get());
printf("first object url: %s\n", example->imageUrl.c_str()); printf("first object url: %s\n", example->imageUrl.c_str());
printf("first object wnid: %s\n", example->wnid.c_str()); printf("first object wnid: %s\n", example->wnid.c_str());
printf("first object id2: %u\n", example->id2); printf("first object id2: %u\n", example->id2);
......
/*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/datasetstools/or_mnist.hpp"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
using namespace cv;
using namespace cv::datasetstools;
int main(int argc, char *argv[])
{
const char *keys =
"{ help h usage ? | | show this message }"
"{ path p |true| path to dataset (SUN397 folder) }";
CommandLineParser parser(argc, argv, keys);
string path(parser.get<string>("path"));
if (parser.has("help") || path=="true")
{
parser.printMessage();
return -1;
}
Ptr<OR_mnist> dataset = OR_mnist::create();
dataset->load(path);
// ***************
// dataset contains for each object its image and label.
// For example, let output train & test sizes and their first elements.
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
OR_mnistObj *example = static_cast<OR_mnistObj *>(dataset->getTrain()[0].get());
printf("first train:\nlabel: %u\n", example->label);
printf("image was saved to train0.png\n");
imwrite("train0.png", example->image);
example = static_cast<OR_mnistObj *>(dataset->getTest()[0].get());
printf("first test:\nlabel: %u\n", example->label);
printf("image was saved to test0.png\n");
imwrite("test0.png", example->image);
return 0;
}
...@@ -65,13 +65,14 @@ int main(int argc, char *argv[]) ...@@ -65,13 +65,14 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
OR_sun dataset(path); Ptr<OR_sun> dataset = OR_sun::create();
dataset->load(path);
// *************** // ***************
// dataset contains for each object its images. // dataset contains for each object its images.
// For example, let output dataset size and last object. // For example, let output dataset size and last object.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
OR_sunObj *example = static_cast<OR_sunObj *>(dataset.train.back().get()); OR_sunObj *example = static_cast<OR_sunObj *>(dataset->getTrain().back().get());
printf("last object name: %s\n", example->name.c_str()); printf("last object name: %s\n", example->name.c_str());
printf("last object images number: %u\n", (unsigned int)example->imageNames.size()); printf("last object images number: %u\n", (unsigned int)example->imageNames.size());
vector<string> &imageNames = example->imageNames; vector<string> &imageNames = example->imageNames;
......
...@@ -65,14 +65,15 @@ int main(int argc, char *argv[]) ...@@ -65,14 +65,15 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
SLAM_kitti dataset(path); Ptr<SLAM_kitti> dataset = SLAM_kitti::create();
dataset->load(path);
// *************** // ***************
// dataset contains sequence with name and its data. // dataset contains sequence with name and its data.
// For example, let output first sequence and dataset size. // For example, let output first sequence and dataset size.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
SLAM_kittiObj *example = static_cast<SLAM_kittiObj *>(dataset.train[0].get()); SLAM_kittiObj *example = static_cast<SLAM_kittiObj *>(dataset->getTrain()[0].get());
printf("first dataset sequence:\n%s\n", example->name.c_str()); printf("first dataset sequence:\n%s\n", example->name.c_str());
/*string pathVelodyne(path + "sequences/" + example->name + "/velodyne/"); /*string pathVelodyne(path + "sequences/" + example->name + "/velodyne/");
......
...@@ -65,14 +65,15 @@ int main(int argc, char *argv[]) ...@@ -65,14 +65,15 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
SLAM_tumindoor dataset(path); Ptr<SLAM_tumindoor> dataset = SLAM_tumindoor::create();
dataset->load(path);
// *************** // ***************
// dataset contains image and its information. // dataset contains image and its information.
// For example, let output first image information and dataset size. // For example, let output first image information and dataset size.
printf("dataset size: %u\n", (unsigned int)dataset.train.size()); printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
SLAM_tumindoorObj *example = static_cast<SLAM_tumindoorObj *>(dataset.train[0].get()); SLAM_tumindoorObj *example = static_cast<SLAM_tumindoorObj *>(dataset->getTrain()[0].get());
printf("first image:\ntype: %u\n", example->type); printf("first image:\ntype: %u\n", example->type);
string imagePath(path); string imagePath(path);
...@@ -85,12 +86,12 @@ int main(int argc, char *argv[]) ...@@ -85,12 +86,12 @@ 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)
{ {
printf("%f ", example->transformMat[i][j]); printf("%f ", example->transformMat(i, j));
} }
printf("\n"); printf("\n");
} }
......
...@@ -66,34 +66,32 @@ int main(int argc, char *argv[]) ...@@ -66,34 +66,32 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
vector<TR_chars> dataset; Ptr<TR_chars> dataset = TR_chars::create();
do dataset->load(path);
{
TR_chars curr;
dataset.push_back(curr);
int number = (int)dataset.size()-1;
dataset.back().load(path, number);
} while (dataset.back().train.size()>0);
dataset.pop_back(); // remove last empty split
// *************** // ***************
// dataset. train, test contain information about each element of appropriate sets and splits. // dataset. train, test contain information about each element of appropriate sets and splits.
// For example, let output first elements of these vectors and their sizes for last split. // For example, let output first elements of these vectors and their sizes for last split.
// And number of splits. // And number of splits.
printf("splits number: %u\n", (unsigned int)dataset.size()); int numSplits = dataset->getNumSplits();
printf("splits number: %u\n", numSplits);
vector< Ptr<Object> > &currTrain = dataset.back().train; vector< Ptr<Object> > &currTrain = dataset->getTrain(numSplits-1);
vector< Ptr<Object> > &currTest = dataset.back().test; vector< Ptr<Object> > &currTest = dataset->getTest(numSplits-1);
vector< Ptr<Object> > &currValidation = dataset->getValidation(numSplits-1);
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;
} }
...@@ -67,16 +67,17 @@ int main(int argc, char *argv[]) ...@@ -67,16 +67,17 @@ int main(int argc, char *argv[])
} }
// loading train & test images description // loading train & test images description
TR_svt dataset(path); Ptr<TR_svt> dataset = TR_svt::create();
dataset->load(path);
// *************** // ***************
// dataset. train & test contains images description. // dataset. train & test contains images description.
// For example, let output the last element in train set and it's description. // For example, let output the last element in train set and it's description.
// And their sizes. // And their sizes.
printf("train size: %u\n", (unsigned int)dataset.train.size()); printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
printf("test size: %u\n", (unsigned int)dataset.test.size()); printf("test size: %u\n", (unsigned int)dataset->getTest().size());
TR_svtObj *example = static_cast<TR_svtObj *>(dataset.train.back().get()); TR_svtObj *example = static_cast<TR_svtObj *>(dataset->getTrain().back().get());
printf("last element:\nfile name: %s", example->fileName.c_str()); printf("last element:\nfile name: %s", example->fileName.c_str());
printf("\nlex: "); printf("\nlex: ");
for (vector<string>::iterator it=example->lex.begin(); it!=example->lex.end(); ++it) for (vector<string>::iterator it=example->lex.begin(); it!=example->lex.end(); ++it)
......
...@@ -49,7 +49,24 @@ namespace datasetstools ...@@ -49,7 +49,24 @@ namespace datasetstools
using namespace std; using namespace std;
void AR_hmdb::loadAction(const string &fileName, vector<string> &train_, vector<string> &test_) class CV_EXPORTS AR_hmdbImp : public AR_hmdb
{
public:
AR_hmdbImp() {}
//AR_hmdbImp(const string &path, int number = 0);
virtual ~AR_hmdbImp() {}
virtual void load(const string &path);
private:
void loadDatasetSplit(const string &path, int number = 0);
void loadDataset(const string &path);
void loadAction(const string &fileName, vector<string> &train_, vector<string> &test_);
};
void AR_hmdbImp::loadAction(const string &fileName, vector<string> &train_, vector<string> &test_)
{ {
ifstream infile(fileName.c_str()); ifstream infile(fileName.c_str());
string video, label; string video, label;
...@@ -66,17 +83,25 @@ void AR_hmdb::loadAction(const string &fileName, vector<string> &train_, vector< ...@@ -66,17 +83,25 @@ void AR_hmdb::loadAction(const string &fileName, vector<string> &train_, vector<
} }
} }
AR_hmdb::AR_hmdb(const string &path, int number) /*AR_hmdbImp::AR_hmdbImp(const string &path, int number)
{ {
loadDataset(path, number); loadDataset(path, number);
}*/
void AR_hmdbImp::load(const string &path)
{
loadDataset(path);
} }
void AR_hmdb::load(const string &path, int number) void AR_hmdbImp::loadDataset(const string &path)
{ {
loadDataset(path, number); for (int i=0; i<3; ++i)
{
loadDatasetSplit(path, i);
}
} }
void AR_hmdb::loadDataset(const string &path, int number) void AR_hmdbImp::loadDatasetSplit(const string &path, int number)
{ {
// valid number [0,1,2] // valid number [0,1,2]
if (number<0 || number>2) if (number<0 || number>2)
...@@ -84,6 +109,10 @@ void AR_hmdb::loadDataset(const string &path, int number) ...@@ -84,6 +109,10 @@ void AR_hmdb::loadDataset(const string &path, int number)
return; return;
} }
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string pathDataset(path + "hmdb51_org/"); string pathDataset(path + "hmdb51_org/");
string pathSplit(path + "testTrainMulti_7030_splits/"); string pathSplit(path + "testTrainMulti_7030_splits/");
...@@ -96,8 +125,8 @@ void AR_hmdb::loadDataset(const string &path, int number) ...@@ -96,8 +125,8 @@ void AR_hmdb::loadDataset(const string &path, int number)
currTrain->name = *it; currTrain->name = *it;
currTest->name = *it; currTest->name = *it;
train.push_back(currTrain); train.back().push_back(currTrain);
test.push_back(currTest); test.back().push_back(currTest);
char tmp[2]; char tmp[2];
sprintf(tmp, "%u", number+1); sprintf(tmp, "%u", number+1);
...@@ -106,5 +135,10 @@ void AR_hmdb::loadDataset(const string &path, int number) ...@@ -106,5 +135,10 @@ void AR_hmdb::loadDataset(const string &path, int number)
} }
} }
Ptr<AR_hmdb> AR_hmdb::create()
{
return Ptr<AR_hmdbImp>(new AR_hmdbImp);
}
} }
} }
...@@ -49,7 +49,22 @@ namespace datasetstools ...@@ -49,7 +49,22 @@ namespace datasetstools
using namespace std; using namespace std;
void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_) class CV_EXPORTS AR_sportsImp : public AR_sports
{
public:
AR_sportsImp() {}
//AR_sportsImp(const string &path);
virtual ~AR_sportsImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
void loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_);
};
void AR_sportsImp::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_)
{ {
ifstream infile(fileName.c_str()); ifstream infile(fileName.c_str());
string videoUrl, labels; string videoUrl, labels;
...@@ -69,31 +84,35 @@ void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &d ...@@ -69,31 +84,35 @@ void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &d
} }
} }
AR_sports::AR_sports(const string &path) /*AR_sportsImp::AR_sportsImp(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }*/
void AR_sports::load(const string &path, int number) void AR_sportsImp::load(const string &path)
{ {
if (number!=0)
{
return;
}
loadDataset(path); loadDataset(path);
} }
void AR_sports::loadDataset(const string &path) void AR_sportsImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string trainPath(path + "original/train_partition.txt"); string trainPath(path + "original/train_partition.txt");
string testPath(path + "original/test_partition.txt"); string testPath(path + "original/test_partition.txt");
// loading train video urls & labels // loading train video urls & labels
loadDatasetPart(trainPath, train); loadDatasetPart(trainPath, train.back());
// loading test video urls & labels // loading test video urls & labels
loadDatasetPart(testPath, test); loadDatasetPart(testPath, test.back());
}
Ptr<AR_sports> AR_sports::create()
{
return Ptr<AR_sportsImp>(new AR_sportsImp);
} }
} }
......
/*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/datasetstools/dataset.hpp"
#include "precomp.hpp"
namespace cv
{
namespace datasetstools
{
using namespace std;
vector< Ptr<Object> >& Dataset::getTrain(int splitNum)
{
if (splitNum >= (int)train.size())
{
return empty;
}
return train[splitNum];
}
vector< Ptr<Object> >& Dataset::getTest(int splitNum)
{
if (splitNum >= (int)test.size())
{
return empty;
}
return test[splitNum];
}
vector< Ptr<Object> >& Dataset::getValidation(int splitNum)
{
if (splitNum >= (int)validation.size())
{
return empty;
}
return validation[splitNum];
}
int Dataset::getNumSplits() const
{
return (int)train.size();
}
}
}
...@@ -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
...@@ -49,40 +51,102 @@ namespace datasetstools ...@@ -49,40 +51,102 @@ namespace datasetstools
using namespace std; using namespace std;
FR_lfw::FR_lfw(const string &path) class CV_EXPORTS FR_lfwImp : public FR_lfw
{ {
loadDataset(path); public:
} FR_lfwImp() {}
//FR_lfwImp(const string &path);
virtual ~FR_lfwImp() {}
virtual void load(const string &path);
void FR_lfw::load(const string &path, int number) private:
void loadDataset(const string &path);
map< string, vector<string> > faces;
};
/*FR_lfwImp::FR_lfwImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void FR_lfwImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void FR_lfw::loadDataset(const string &path) void FR_lfwImp::loadDataset(const string &path)
{ {
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 &name = *it;
vector<string> images;
string pathFace(path + curr->name + "/"); 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.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++;
}
}
Ptr<FR_lfw> FR_lfw::create()
{
return Ptr<FR_lfwImp>(new FR_lfwImp);
} }
} }
......
...@@ -49,22 +49,32 @@ namespace datasetstools ...@@ -49,22 +49,32 @@ namespace datasetstools
using namespace std; using namespace std;
GR_chalearn::GR_chalearn(const string &path) class CV_EXPORTS GR_chalearnImp : public GR_chalearn
{ {
loadDataset(path); public:
} GR_chalearnImp() {}
//GR_chalearnImp(const string &path);
virtual ~GR_chalearnImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
void loadDatasetPart(const string &path, vector< Ptr<Object> > &dataset_, bool loadLabels);
};
void GR_chalearn::load(const string &path, int number) /*GR_chalearnImp::GR_chalearnImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void GR_chalearnImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void GR_chalearn::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);
...@@ -88,6 +98,8 @@ void GR_chalearn::loadDataset(const string &path) ...@@ -88,6 +98,8 @@ void GR_chalearn::loadDataset(const string &path)
curr->depth = atoi(elems[2].c_str()); curr->depth = atoi(elems[2].c_str());
// loading ground truth // loading ground truth
if (loadLabels)
{
string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv"); string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv");
ifstream infileGroundTruth(fileGroundTruth.c_str()); ifstream infileGroundTruth(fileGroundTruth.c_str());
while (getline(infileGroundTruth, line)) while (getline(infileGroundTruth, line))
...@@ -102,6 +114,7 @@ void GR_chalearn::loadDataset(const string &path) ...@@ -102,6 +114,7 @@ void GR_chalearn::loadDataset(const string &path)
curr->groundTruths.push_back(currGroundTruth); curr->groundTruths.push_back(currGroundTruth);
} }
}
// loading skeleton // loading skeleton
string fileSkeleton(path + curr->name + "/" + curr->name + "_skeleton.csv"); string fileSkeleton(path + curr->name + "/" + curr->name + "_skeleton.csv");
...@@ -129,9 +142,28 @@ void GR_chalearn::loadDataset(const string &path) ...@@ -129,9 +142,28 @@ void GR_chalearn::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)
{
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string pathTrain(path + "Train/");
loadDatasetPart(pathTrain, train.back(), true);
// freely available validation set doesn't have labels
string pathValidation(path + "Validation/");
loadDatasetPart(pathValidation, validation.back(), false);
}
Ptr<GR_chalearn> GR_chalearn::create()
{
return Ptr<GR_chalearnImp>(new GR_chalearnImp);
}
} }
} }
...@@ -51,23 +51,35 @@ namespace datasetstools ...@@ -51,23 +51,35 @@ namespace datasetstools
using namespace std; using namespace std;
GR_skig::GR_skig(const string &path) class CV_EXPORTS GR_skigImp : public GR_skig
{ {
loadDataset(path); public:
} GR_skigImp() {}
//GR_skigImp(const string &path);
virtual ~GR_skigImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
};
void GR_skig::load(const string &path, int number) /*GR_skigImp::GR_skigImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void GR_skigImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void GR_skig::loadDataset(const string &path) void GR_skigImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
for (unsigned int i=1; i<=6; ++i) for (unsigned int i=1; i<=6; ++i)
{ {
char number[2]; char number[2];
...@@ -87,20 +99,35 @@ void GR_skig::loadDataset(const string &path) ...@@ -87,20 +99,35 @@ void GR_skig::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.back().push_back(curr);
} else
{
printf("incorrect file name: %s", file.c_str());
} }
} }
}
}
Ptr<GR_skig> GR_skig::create()
{
return Ptr<GR_skigImp>(new GR_skigImp);
} }
} }
......
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
HPE_parse::HPE_parse(const string &path) class CV_EXPORTS HPE_parseImp : public HPE_parse
{ {
loadDataset(path); public:
} HPE_parseImp() {}
//HPE_parseImp(const string &path);
virtual ~HPE_parseImp() {}
virtual void load(const string &path);
void HPE_parse::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*HPE_parseImp::HPE_parseImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void HPE_parseImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void HPE_parse::loadDataset(const string &path) void HPE_parseImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
unsigned int i=0; unsigned int i=0;
vector<string> fileNames; vector<string> fileNames;
getDirList(path, fileNames); getDirList(path, fileNames);
...@@ -84,15 +96,20 @@ void HPE_parse::loadDataset(const string &path) ...@@ -84,15 +96,20 @@ void HPE_parse::loadDataset(const string &path)
if (i<100) if (i<100)
{ {
train.push_back(curr); train.back().push_back(curr);
} else } else
{ {
test.push_back(curr); test.back().push_back(curr);
} }
++i; ++i;
} }
} }
} }
Ptr<HPE_parse> HPE_parse::create()
{
return Ptr<HPE_parseImp>(new HPE_parseImp);
}
} }
} }
...@@ -49,30 +49,56 @@ namespace datasetstools ...@@ -49,30 +49,56 @@ namespace datasetstools
using namespace std; using namespace std;
IR_affine::IR_affine(const string &path) class CV_EXPORTS IR_affineImp : public IR_affine
{ {
loadDataset(path); public:
} IR_affineImp() {}
//IR_affineImp(const string &path);
virtual ~IR_affineImp() {}
virtual void load(const string &path);
void IR_affine::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*IR_affineImp::IR_affineImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void IR_affineImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void IR_affine::loadDataset(const string &path) void IR_affineImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
// detect image extension
string ext;
vector<string> fileNames;
getDirList(path, fileNames);
for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it)
{
string &name = *it;
if (name.length()>=8 && name.substr(0, 3)=="img")
{
ext = name.substr(name.length()-4, 4);
break;
}
}
for (unsigned int i=1; i<=6; ++i) for (unsigned int i=1; i<=6; ++i)
{ {
Ptr<IR_affineObj> curr(new IR_affineObj); Ptr<IR_affineObj> curr(new IR_affineObj);
char tmp[2]; char tmp[2];
sprintf(tmp, "%u", i); sprintf(tmp, "%u", i);
curr->imageName = path + "img" + tmp + ".ppm"; curr->imageName = path + "img" + tmp + ext;
if (i>1) if (i>1)
{ {
...@@ -87,9 +113,14 @@ void IR_affine::loadDataset(const string &path) ...@@ -87,9 +113,14 @@ void IR_affine::loadDataset(const string &path)
} }
} }
train.push_back(curr); train.back().push_back(curr);
} }
} }
Ptr<IR_affine> IR_affine::create()
{
return Ptr<IR_affineImp>(new IR_affineImp);
}
} }
} }
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
IR_robot::IR_robot(const string &path) class CV_EXPORTS IR_robotImp : public IR_robot
{ {
loadDataset(path); public:
} IR_robotImp() {}
//IR_robotImp(const string &path);
virtual ~IR_robotImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
};
void IR_robot::load(const string &path, int number) /*IR_robotImp::IR_robotImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void IR_robotImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void IR_robot::loadDataset(const string &path) void IR_robotImp::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)
...@@ -76,14 +88,30 @@ void IR_robot::loadDataset(const string &path) ...@@ -76,14 +88,30 @@ void IR_robot::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.back().push_back(curr);
} }
} }
Ptr<IR_robot> IR_robot::create()
{
return Ptr<IR_robotImp>(new IR_robotImp);
}
} }
} }
...@@ -49,7 +49,22 @@ namespace datasetstools ...@@ -49,7 +49,22 @@ namespace datasetstools
using namespace std; using namespace std;
void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_) class CV_EXPORTS IS_bsdsImp : public IS_bsds
{
public:
IS_bsdsImp() {}
//IS_bsdsImp(const string &path);
virtual ~IS_bsdsImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
void loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_);
};
void IS_bsdsImp::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dataset_)
{ {
ifstream infile(fileName.c_str()); ifstream infile(fileName.c_str());
string imageName; string imageName;
...@@ -61,31 +76,35 @@ void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dat ...@@ -61,31 +76,35 @@ void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr<Object> > &dat
} }
} }
IS_bsds::IS_bsds(const string &path) /*IS_bsdsImp::IS_bsdsImp(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }*/
void IS_bsds::load(const string &path, int number) void IS_bsdsImp::load(const string &path)
{ {
if (number!=0)
{
return;
}
loadDataset(path); loadDataset(path);
} }
void IS_bsds::loadDataset(const string &path) void IS_bsdsImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string trainName(path + "iids_train.txt"); string trainName(path + "iids_train.txt");
string testName(path + "iids_test.txt"); string testName(path + "iids_test.txt");
// loading train // loading train
loadDatasetPart(trainName, train); loadDatasetPart(trainName, train.back());
// loading test // loading test
loadDatasetPart(testName, test); loadDatasetPart(testName, test.back());
}
Ptr<IS_bsds> IS_bsds::create()
{
return Ptr<IS_bsdsImp>(new IS_bsdsImp);
} }
} }
......
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
IS_weizmann::IS_weizmann(const string &path) class CV_EXPORTS IS_weizmannImp : public IS_weizmann
{ {
loadDataset(path); public:
} IS_weizmannImp() {}
//IS_weizmannImp(const string &path);
virtual ~IS_weizmannImp() {}
virtual void load(const string &path);
void IS_weizmann::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*IS_weizmannImp::IS_weizmannImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void IS_weizmannImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void IS_weizmann::loadDataset(const string &path) void IS_weizmannImp::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)
...@@ -80,10 +92,15 @@ void IS_weizmann::loadDataset(const string &path) ...@@ -80,10 +92,15 @@ void IS_weizmann::loadDataset(const string &path)
curr->humanSeg = imageName + "human_seg/"; curr->humanSeg = imageName + "human_seg/";
train.push_back(curr); train.back().push_back(curr);
} }
} }
} }
Ptr<IS_weizmann> IS_weizmann::create()
{
return Ptr<IS_weizmannImp>(new IS_weizmannImp);
}
} }
} }
...@@ -49,33 +49,35 @@ namespace datasetstools ...@@ -49,33 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
void MSM_epfl::readFileDouble(const string &fileName, vector<double> &out) class CV_EXPORTS MSM_epflImp : public MSM_epfl
{ {
ifstream infile(fileName.c_str()); public:
double val; MSM_epflImp() {}
while (infile >> val) //MSM_epflImp(const string &path);
{ virtual ~MSM_epflImp() {}
out.push_back(val);
} virtual void load(const string &path);
}
private:
void loadDataset(const string &path);
};
MSM_epfl::MSM_epfl(const string &path) /*MSM_epflImp::MSM_epflImp(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }*/
void MSM_epfl::load(const string &path, int number) void MSM_epflImp::load(const string &path)
{ {
if (number!=0)
{
return;
}
loadDataset(path); loadDataset(path);
} }
void MSM_epfl::loadDataset(const string &path) void MSM_epflImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string pathBounding(path + "bounding/"); string pathBounding(path + "bounding/");
string pathCamera(path + "camera/"); string pathCamera(path + "camera/");
string pathP(path + "P/"); string pathP(path + "P/");
...@@ -88,12 +90,66 @@ void MSM_epfl::loadDataset(const string &path) ...@@ -88,12 +90,66 @@ void MSM_epfl::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);
}
}
train.push_back(curr); 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.back().push_back(curr);
}
}
Ptr<MSM_epfl> MSM_epfl::create()
{
return Ptr<MSM_epflImp>(new MSM_epflImp);
} }
} }
......
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
MSM_middlebury::MSM_middlebury(const string &path) class CV_EXPORTS MSM_middleburyImp : public MSM_middlebury
{ {
loadDataset(path); public:
} MSM_middleburyImp() {}
//MSM_middleburyImp(const string &path);
virtual ~MSM_middleburyImp() {}
virtual void load(const string &path);
void MSM_middlebury::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*MSM_middleburyImp::MSM_middleburyImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void MSM_middleburyImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void MSM_middlebury::loadDataset(const string &path) void MSM_middleburyImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string name(path.substr(0, path.length()-1)); string name(path.substr(0, path.length()-1));
size_t start = name.rfind('/'); size_t start = name.rfind('/');
name = name.substr(start+1, name.length()-start); name = name.substr(start+1, name.length()-start);
...@@ -85,14 +97,14 @@ void MSM_middlebury::loadDataset(const string &path) ...@@ -85,14 +97,14 @@ void MSM_middlebury::loadDataset(const string &path)
{ {
for (int j=0; j<3; ++j) for (int j=0; j<3; ++j)
{ {
infile >> curr->k[i][j]; infile >> curr->k(i, j);
} }
} }
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
{ {
for (int j=0; j<3; ++j) for (int j=0; j<3; ++j)
{ {
infile >> curr->r[i][j]; infile >> curr->r(i, j);
} }
} }
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
...@@ -100,9 +112,14 @@ void MSM_middlebury::loadDataset(const string &path) ...@@ -100,9 +112,14 @@ void MSM_middlebury::loadDataset(const string &path)
infile >> curr->t[i]; infile >> curr->t[i];
} }
train.push_back(curr); train.back().push_back(curr);
} }
} }
Ptr<MSM_middlebury> MSM_middlebury::create()
{
return Ptr<MSM_middleburyImp>(new MSM_middleburyImp);
}
} }
} }
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
OR_imagenet::OR_imagenet(const string &path) class CV_EXPORTS OR_imagenetImp : public OR_imagenet
{ {
loadDataset(path); public:
} OR_imagenetImp() {}
//OR_imagenetImp(const string &path);
virtual ~OR_imagenetImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
};
void OR_imagenet::load(const string &path, int number) /*OR_imagenetImp::OR_imagenetImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void OR_imagenetImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void OR_imagenet::loadDataset(const string &path) void OR_imagenetImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
ifstream infile((path + "fall11_urls.txt").c_str()); ifstream infile((path + "fall11_urls.txt").c_str());
string line; string line;
while (getline(infile, line)) while (getline(infile, line))
...@@ -83,11 +95,14 @@ void OR_imagenet::loadDataset(const string &path) ...@@ -83,11 +95,14 @@ void OR_imagenet::loadDataset(const string &path)
curr->wnid = elems[0]; curr->wnid = elems[0];
curr->id2 = atoi(elems[1].c_str()); curr->id2 = atoi(elems[1].c_str());
wnids.insert(curr->wnid); train.back().push_back(curr);
train.push_back(curr);
} }
} }
Ptr<OR_imagenet> OR_imagenet::create()
{
return Ptr<OR_imagenetImp>(new OR_imagenetImp);
}
} }
} }
/*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/datasetstools/or_mnist.hpp"
#include "precomp.hpp"
namespace cv
{
namespace datasetstools
{
using namespace std;
class CV_EXPORTS OR_mnistImp : public OR_mnist
{
public:
OR_mnistImp() {}
//OR_mnistImp(const string &path);
virtual ~OR_mnistImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
void loadDatasetPart(const string &imagesFile, const string &labelsFile, unsigned int num, vector< Ptr<Object> > &dataset_);
};
/*OR_mnistImp::OR_mnistImp(const string &path)
{
loadDataset(path);
}*/
void OR_mnistImp::load(const string &path)
{
loadDataset(path);
}
void OR_mnistImp::loadDatasetPart(const string &imagesFile, const string &labelsFile, unsigned int num, vector< Ptr<Object> > &dataset_)
{
FILE *f = fopen(imagesFile.c_str(), "rb");
fseek(f, 16, SEEK_CUR);
unsigned int imageSize = 28*28;
char *images = new char[num*imageSize];
size_t res = fread(images, 1, num*imageSize, f);
fclose(f);
if (num*imageSize != res)
{
return;
}
f = fopen(labelsFile.c_str(), "rb");
fseek(f, 8, SEEK_CUR);
char *labels = new char[num];
res = fread(labels, 1, num, f);
fclose(f);
if (num != res)
{
return;
}
for (unsigned int i=0; i<num; ++i)
{
Ptr<OR_mnistObj> curr(new OR_mnistObj);
curr->label = labels[i];
curr->image = Mat(28, 28, CV_8U);
unsigned int imageIdx = i*imageSize;
for (int j=0; j<curr->image.rows; ++j)
{
char *im = curr->image.ptr<char>(j);
for (int k=0; k<curr->image.cols; ++k)
{
im[k] = images[imageIdx + j*28 + k];
}
}
dataset_.push_back(curr);
}
delete[] images;
delete[] labels;
}
void OR_mnistImp::loadDataset(const string &path)
{
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string trainImagesFile(path + "train-images.idx3-ubyte");
string trainLabelsFile(path + "train-labels.idx1-ubyte");
loadDatasetPart(trainImagesFile, trainLabelsFile, 60000, train.back());
string testImagesFile(path + "t10k-images.idx3-ubyte");
string testLabelsFile(path + "t10k-labels.idx1-ubyte");
loadDatasetPart(testImagesFile, testLabelsFile, 10000, test.back());
}
Ptr<OR_mnist> OR_mnist::create()
{
return Ptr<OR_mnistImp>(new OR_mnistImp);
}
}
}
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
OR_sun::OR_sun(const string &path) class CV_EXPORTS OR_sunImp : public OR_sun
{ {
loadDataset(path); public:
} OR_sunImp() {}
//OR_sunImp(const string &path);
virtual ~OR_sunImp() {}
virtual void load(const string &path);
void OR_sun::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*OR_sunImp::OR_sunImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void OR_sunImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void OR_sun::loadDataset(const string &path) void OR_sunImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string classNameFile(path + "ClassName.txt"); string classNameFile(path + "ClassName.txt");
ifstream infile(classNameFile.c_str()); ifstream infile(classNameFile.c_str());
string line; string line;
...@@ -82,9 +94,14 @@ void OR_sun::loadDataset(const string &path) ...@@ -82,9 +94,14 @@ void OR_sun::loadDataset(const string &path)
curr->imageNames.push_back(*it); curr->imageNames.push_back(*it);
} }
train.push_back(curr); train.back().push_back(curr);
} }
} }
Ptr<OR_sun> OR_sun::create()
{
return Ptr<OR_sunImp>(new OR_sunImp);
}
} }
} }
...@@ -49,23 +49,35 @@ namespace datasetstools ...@@ -49,23 +49,35 @@ namespace datasetstools
using namespace std; using namespace std;
SLAM_kitti::SLAM_kitti(const string &path) class CV_EXPORTS SLAM_kittiImp : public SLAM_kitti
{ {
loadDataset(path); public:
} SLAM_kittiImp() {}
//SLAM_kittiImp(const string &path);
virtual ~SLAM_kittiImp() {}
virtual void load(const string &path);
void SLAM_kitti::load(const string &path, int number) private:
void loadDataset(const string &path);
};
/*SLAM_kittiImp::SLAM_kittiImp(const string &path)
{ {
if (number!=0) loadDataset(path);
{ }*/
return;
}
void SLAM_kittiImp::load(const string &path)
{
loadDataset(path); loadDataset(path);
} }
void SLAM_kitti::loadDataset(const string &path) void SLAM_kittiImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string pathSequence(path + "sequences/"); string pathSequence(path + "sequences/");
vector<string> fileNames; vector<string> fileNames;
getDirList(pathSequence, fileNames); getDirList(pathSequence, fileNames);
...@@ -142,9 +154,14 @@ void SLAM_kitti::loadDataset(const string &path) ...@@ -142,9 +154,14 @@ void SLAM_kitti::loadDataset(const string &path)
curr->posesArray.push_back(p); curr->posesArray.push_back(p);
} }
train.push_back(curr); train.back().push_back(curr);
} }
} }
Ptr<SLAM_kitti> SLAM_kitti::create()
{
return Ptr<SLAM_kittiImp>(new SLAM_kittiImp);
}
} }
} }
...@@ -51,25 +51,63 @@ namespace datasetstools ...@@ -51,25 +51,63 @@ namespace datasetstools
using namespace std; using namespace std;
SLAM_tumindoor::SLAM_tumindoor(const string &path) class CV_EXPORTS SLAM_tumindoorImp : public SLAM_tumindoor
{
public:
SLAM_tumindoorImp() {}
//SLAM_tumindoorImp(const string &path);
virtual ~SLAM_tumindoorImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
};
/*SLAM_tumindoorImp::SLAM_tumindoorImp(const string &path)
{
loadDataset(path);
}*/
void SLAM_tumindoorImp::load(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }
void SLAM_tumindoor::load(const string &path, int number) void SLAM_tumindoorImp::loadDataset(const string &path)
{ {
if (number!=0) train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string infoPath(path + "info/");
// 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; return;
} }
loadDataset(path); ifstream infile((infoPath + csvName).c_str());
}
void SLAM_tumindoor::loadDataset(const string &path)
{
string infoPath(path + "info/2011-12-17_15.02.56-info.csv"); // TODO
ifstream infile(infoPath.c_str());
string line; string line;
while (getline(infile, line)) while (getline(infile, line))
{ {
...@@ -95,13 +133,18 @@ void SLAM_tumindoor::loadDataset(const string &path) ...@@ -95,13 +133,18 @@ void SLAM_tumindoor::loadDataset(const string &path)
{ {
for (unsigned int j=0; j<4; ++j) for (unsigned int j=0; j<4; ++j)
{ {
curr->transformMat[i][j] = atof(elems[1 + j + i*4].c_str()); curr->transformMat(i, j) = atof(elems[1 + j + i*4].c_str());
} }
} }
train.push_back(curr); train.back().push_back(curr);
} }
} }
Ptr<SLAM_tumindoor> SLAM_tumindoor::create()
{
return Ptr<SLAM_tumindoorImp>(new SLAM_tumindoorImp);
}
} }
} }
...@@ -49,7 +49,28 @@ namespace datasetstools ...@@ -49,7 +49,28 @@ namespace datasetstools
using namespace std; using namespace std;
void TR_chars::parseLine(const string &line, vector<int> &currSet, int number) class CV_EXPORTS TR_charsImp : public TR_chars
{
public:
TR_charsImp() {}
//TR_charsImp(const string &path, int number = 0);
virtual ~TR_charsImp() {}
virtual void load(const string &path);
private:
void loadDatasetSplit(const string &path, int number);
void loadDataset(const string &path);
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)
{ {
vector<string> elems; vector<string> elems;
split(line, elems, ' '); split(line, elems, ' ');
...@@ -65,33 +86,84 @@ void TR_chars::parseLine(const string &line, vector<int> &currSet, int number) ...@@ -65,33 +86,84 @@ void TR_chars::parseLine(const string &line, vector<int> &currSet, int number)
} }
} }
TR_chars::TR_chars(const string &path, int number) inline void TR_charsImp::convert(vector<int> &from, vector< Ptr<Object> > &to, vector<int> &allLabels, vector<string> &allNames)
{ {
loadDataset(path, number); 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);
}
} }
void TR_chars::load(const string &path, int number) 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)
{ {
loadDataset(path, number); loadDataset(path, number);
}*/
void TR_charsImp::load(const string &path)
{
loadDataset(path);
}
void TR_charsImp::loadDataset(const string &path)
{
int number = 0;
do
{
loadDatasetSplit(path, number);
number++;
} while (train.back().size()>0);
train.pop_back(); // remove last empty split
test.pop_back(); // remove last empty split
validation.pop_back(); // remove last empty split
} }
void TR_chars::loadDataset(const string &path, int number) void TR_charsImp::loadDatasetSplit(const string &path, int number)
{ {
vector<int> allLabels, trainSet, testSet; train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
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 = [");
...@@ -109,7 +181,7 @@ void TR_chars::loadDataset(const string &path, int number) ...@@ -109,7 +181,7 @@ void TR_chars::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();
...@@ -122,66 +194,29 @@ void TR_chars::loadDataset(const string &path, int number) ...@@ -122,66 +194,29 @@ void TR_chars::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.back(), allLabels, allNames);
{ convert(testSet, test.back(), allLabels, allNames);
if (*it>=(int)allNames.size() || *it>=(int)allLabels.size()) convert(validationSet, validation.back(), 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); Ptr<TR_chars> TR_chars::create()
curr->imgName = allNames[*it]; {
curr->label = allLabels[*it]; return Ptr<TR_charsImp>(new TR_charsImp);
test.push_back(curr);
}
} }
} }
......
...@@ -52,7 +52,22 @@ namespace datasetstools ...@@ -52,7 +52,22 @@ namespace datasetstools
using namespace std; using namespace std;
using namespace tinyxml2; using namespace tinyxml2;
void TR_svt::xmlParse(const string &set, vector< Ptr<Object> > &out) class CV_EXPORTS TR_svtImp : public TR_svt
{
public:
TR_svtImp() {}
//TR_svtImp(const string &path);
virtual ~TR_svtImp() {}
virtual void load(const string &path);
private:
void loadDataset(const string &path);
void xmlParse(const string &set, vector< Ptr<Object> > &out);
};
void TR_svtImp::xmlParse(const string &set, vector< Ptr<Object> > &out)
{ {
XMLDocument doc; XMLDocument doc;
doc.LoadFile(set.c_str()); doc.LoadFile(set.c_str());
...@@ -97,31 +112,35 @@ void TR_svt::xmlParse(const string &set, vector< Ptr<Object> > &out) ...@@ -97,31 +112,35 @@ void TR_svt::xmlParse(const string &set, vector< Ptr<Object> > &out)
} }
} }
TR_svt::TR_svt(const string &path) /*TR_svtImp::TR_svtImp(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }*/
void TR_svt::load(const string &path, int number) void TR_svtImp::load(const string &path)
{ {
if (number!=0)
{
return;
}
loadDataset(path); loadDataset(path);
} }
void TR_svt::loadDataset(const string &path) void TR_svtImp::loadDataset(const string &path)
{ {
train.push_back(vector< Ptr<Object> >());
test.push_back(vector< Ptr<Object> >());
validation.push_back(vector< Ptr<Object> >());
string trainXml(path + "train.xml"); string trainXml(path + "train.xml");
string testXml(path + "test.xml"); string testXml(path + "test.xml");
// loading train images description // loading train images description
xmlParse(trainXml, train); xmlParse(trainXml, train.back());
// loading test images description // loading test images description
xmlParse(testXml, test); xmlParse(testXml, test.back());
}
Ptr<TR_svt> TR_svt::create()
{
return Ptr<TR_svtImp>(new TR_svtImp);
} }
} }
......
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