diff --git a/modules/datasetstools/doc/datasetstools.rst b/modules/datasetstools/doc/datasetstools.rst index 76d27130b..f2b0ae71f 100644 --- a/modules/datasetstools/doc/datasetstools.rst +++ b/modules/datasetstools/doc/datasetstools.rst @@ -6,8 +6,6 @@ datasetstools. Tools 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 ------------------ @@ -50,13 +48,13 @@ FR_lfw 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 - 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/ @@ -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). - 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 ======= @@ -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/ +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 ====== .. ocv:class:: OR_sun 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". diff --git a/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp b/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp index 4b3501856..85e159702 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp @@ -63,16 +63,9 @@ struct AR_hmdbObj : public Object class CV_EXPORTS AR_hmdb : public Dataset { public: - AR_hmdb() {} - AR_hmdb(const std::string &path, int number = 0); - virtual ~AR_hmdb() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path, int number = 0); - - void loadAction(const std::string &fileName, std::vector &train_, std::vector &test_); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp b/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp index 48361951e..408e2fca5 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp @@ -63,16 +63,9 @@ struct AR_sportsObj : public Object class CV_EXPORTS AR_sports : public Dataset { public: - AR_sports() {} - AR_sports(const std::string &path); - virtual ~AR_sports() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); - - void loadDatasetPart(const std::string &fileName, std::vector< Ptr > &dataset_); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp index 78a76e0d0..9cb1e7381 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp @@ -62,10 +62,21 @@ public: 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 > train; - std::vector< Ptr > test; + std::vector< Ptr >& getTrain(int splitNum = 0); + std::vector< Ptr >& getTest(int splitNum = 0); + std::vector< Ptr >& getValidation(int splitNum = 0); + + int getNumSplits() const; + +protected: + std::vector< std::vector< Ptr > > train; + std::vector< std::vector< Ptr > > test; + std::vector< std::vector< Ptr > > validation; + +private: + std::vector< Ptr > empty; }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp index 372490c6d..dbc0a499a 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp @@ -56,21 +56,16 @@ namespace datasetstools struct FR_lfwObj : public Object { - std::string name; - std::vector images; + std::string image1, image2; + bool same; }; class CV_EXPORTS FR_lfw : public Dataset { public: - FR_lfw() {} - FR_lfw(const std::string &path); - virtual ~FR_lfw() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp b/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp index f0b000b84..efadb605d 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp @@ -80,14 +80,9 @@ struct GR_chalearnObj : public Object class CV_EXPORTS GR_chalearn : public Dataset { public: - GR_chalearn() {} - GR_chalearn(const std::string &path); - virtual ~GR_chalearn() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp b/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp index 800df1f83..79cfcdeb4 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp @@ -102,14 +102,9 @@ struct GR_skigObj : public Object class CV_EXPORTS GR_skig : public Dataset { public: - GR_skig() {} - GR_skig(const std::string &path); - virtual ~GR_skig() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp b/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp index 9f21589a2..7d1d1b15a 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp @@ -62,14 +62,9 @@ struct HPE_parseObj : public Object class CV_EXPORTS HPE_parse : public Dataset { public: - HPE_parse() {} - HPE_parse(const std::string &path); - virtual ~HPE_parse() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp b/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp index cfb82e181..b3cc8782a 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp @@ -64,14 +64,9 @@ struct IR_affineObj : public Object class CV_EXPORTS IR_affine : public Dataset { public: - IR_affine() {} - IR_affine(const std::string &path); - virtual ~IR_affine() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp index 37b6ae224..fe319ba14 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp @@ -59,23 +59,23 @@ namespace datasetstools // 0.0000e+00 2.8285e+03 6.1618e+02 // 0.0000e+00 0.0000e+00 1.0000e+00 +struct cameraPos +{ + std::vector images; +}; + struct IR_robotObj : public Object { std::string name; - std::vector images; // TODO: implement more complex structure + std::vector pos; }; class CV_EXPORTS IR_robot : public Dataset { public: - IR_robot() {} - IR_robot(const std::string &path); - virtual ~IR_robot() {} - - virtual void load(const std::string &path, int number = 0); + virtual void load(const std::string &path) = 0; -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp b/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp index b51956885..880b2fcb7 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp @@ -62,16 +62,9 @@ struct IS_bsdsObj : public Object class CV_EXPORTS IS_bsds : public Dataset { public: - IS_bsds() {} - IS_bsds(const std::string &path); - virtual ~IS_bsds() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); - - void loadDatasetPart(const std::string &fileName, std::vector< Ptr > &dataset_); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp b/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp index 6857ad350..66184489f 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp @@ -65,14 +65,9 @@ struct IS_weizmannObj : public Object class CV_EXPORTS IS_weizmann : public Dataset { public: - IS_weizmann() {} - IS_weizmann(const std::string &path); - virtual ~IS_weizmann() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp index eb1751cc9..1aecf6f66 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp @@ -54,25 +54,29 @@ namespace cv namespace datasetstools { +struct cameraParam +{ + Matx33d mat1; + double mat2[3]; + Matx33d mat3; + double mat4[3]; + int imageWidth, imageHeight; +}; + struct MSM_epflObj : public Object { std::string imageName; - std::vector bounding, camera, p; // TODO: implement better structures + Matx23d bounding; + Matx34d p; + cameraParam camera; }; class CV_EXPORTS MSM_epfl : public Dataset { public: - MSM_epfl() {} - 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); + virtual void load(const std::string &path) = 0; - void readFileDouble(const std::string &fileName, std::vector &out); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp b/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp index 4631ccaa3..cbfbb38be 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp @@ -57,22 +57,17 @@ namespace datasetstools struct MSM_middleburyObj : public Object { std::string imageName; - double k[3][3]; - double r[3][3]; + Matx33d k; + Matx33d r; double t[3]; }; class CV_EXPORTS MSM_middlebury : public Dataset { public: - MSM_middlebury() {} - MSM_middlebury(const std::string &path); - virtual ~MSM_middlebury() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp index 83b1b3669..ac401f930 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp @@ -44,7 +44,6 @@ #include #include -#include #include "opencv2/datasetstools/dataset.hpp" @@ -65,16 +64,9 @@ struct OR_imagenetObj : public Object class CV_EXPORTS OR_imagenet : public Dataset { public: - OR_imagenet() {} - OR_imagenet(const std::string &path); - virtual ~OR_imagenet() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - - std::set wnids; - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/or_mnist.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_mnist.hpp new file mode 100644 index 000000000..89763c5ee --- /dev/null +++ b/modules/datasetstools/include/opencv2/datasetstools/or_mnist.hpp @@ -0,0 +1,74 @@ +/*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 +#include + +#include "opencv2/datasetstools/dataset.hpp" + +#include + +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 create(); +}; + +} +} + +#endif diff --git a/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp index e151d515b..f231d6d20 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp @@ -63,14 +63,9 @@ struct OR_sunObj : public Object class CV_EXPORTS OR_sun : public Dataset { public: - OR_sun() {} - OR_sun(const std::string &path); - virtual ~OR_sun() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp b/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp index 3ca08e72b..f133eb134 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp @@ -71,14 +71,9 @@ struct SLAM_kittiObj : public Object class CV_EXPORTS SLAM_kitti : public Dataset { public: - SLAM_kitti() {} - SLAM_kitti(const std::string &path); - virtual ~SLAM_kitti() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp b/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp index 93b84b1f8..4945dca33 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp @@ -64,21 +64,16 @@ enum imageType struct SLAM_tumindoorObj : public Object { std::string name; - double transformMat[4][4]; + Matx44d transformMat; imageType type; }; class CV_EXPORTS SLAM_tumindoor : public Dataset { public: - SLAM_tumindoor() {} - SLAM_tumindoor(const std::string &path); - virtual ~SLAM_tumindoor() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp b/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp index 56bad3a1e..c8207b45f 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp @@ -63,16 +63,9 @@ struct TR_charsObj : public Object class CV_EXPORTS TR_chars : public Dataset { public: - TR_chars() {} - TR_chars(const std::string &path, int number = 0); - virtual ~TR_chars() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path, int number = 0); - - void parseLine(const std::string &line, std::vector &currSet, int number); + static Ptr create(); }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp b/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp index 4f1358c4b..eb014af95 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp @@ -70,16 +70,9 @@ struct TR_svtObj : public Object class CV_EXPORTS TR_svt : public Dataset { public: - TR_svt() {} - TR_svt(const std::string &path); - virtual ~TR_svt() {} + virtual void load(const std::string &path) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); - - void xmlParse(const std::string &set, std::vector< Ptr > &out); + static Ptr create(); }; } diff --git a/modules/datasetstools/samples/ar_hmdb.cpp b/modules/datasetstools/samples/ar_hmdb.cpp index 0c4c921dc..5bb067f43 100644 --- a/modules/datasetstools/samples/ar_hmdb.cpp +++ b/modules/datasetstools/samples/ar_hmdb.cpp @@ -65,17 +65,17 @@ int main(int argc, char *argv[]) return -1; } - AR_hmdb dataset[3]; - for (int i=0; i<3; ++i) - { - dataset[i].load(path, i); - } + Ptr dataset = AR_hmdb::create(); + dataset->load(path); // *************** // 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. // And its size. - AR_hmdbObj *example = static_cast(dataset[1].train[0].get()); + int numSplits = dataset->getNumSplits(); + printf("splits number: %u\n", numSplits); + + AR_hmdbObj *example = static_cast(dataset->getTrain(1)[0].get()); printf("name: %s\n", example->name.c_str()); vector &videoNames = example->videoNames; printf("size: %u\n", (unsigned int)videoNames.size()); diff --git a/modules/datasetstools/samples/ar_sports.cpp b/modules/datasetstools/samples/ar_sports.cpp index d535d6987..d382ed0a5 100644 --- a/modules/datasetstools/samples/ar_sports.cpp +++ b/modules/datasetstools/samples/ar_sports.cpp @@ -66,16 +66,17 @@ int main(int argc, char *argv[]) return -1; } - AR_sports dataset(path); + Ptr dataset = AR_sports::create(); + dataset->load(path); // *************** // 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. // And sizes of both datasets. - printf("train size: %u\n", (unsigned int)dataset.train.size()); - printf("test size: %u\n", (unsigned int)dataset.test.size()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("test size: %u\n", (unsigned int)dataset->getTest().size()); - AR_sportsObj *example = static_cast(dataset.test[0].get()); + AR_sportsObj *example = static_cast(dataset->getTest()[0].get()); printf("url: %s\n", example->videoUrl.c_str()); printf("labels: "); vector &labels = example->labels; diff --git a/modules/datasetstools/samples/fr_lfw.cpp b/modules/datasetstools/samples/fr_lfw.cpp index 3519a1be7..348c69666 100644 --- a/modules/datasetstools/samples/fr_lfw.cpp +++ b/modules/datasetstools/samples/fr_lfw.cpp @@ -65,19 +65,25 @@ int main(int argc, char *argv[]) return -1; } - FR_lfw dataset(path); + Ptr dataset = FR_lfw::create(); + dataset->load(path); // *************** - // dataset contains object with name and its images. - // For example, let output dataset size and sixth element. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - FR_lfwObj *example = static_cast(dataset.train[5].get()); - printf("sixth dataset object:\n%s\n", example->name.c_str()); - string currPath(path + example->name + "/"); - for (vector::iterator it=example->images.begin(); it!=example->images.end(); ++it) - { - printf("%s\n", (currPath+(*it)).c_str()); - } + // test contains two images and flag that they belong to one person. + // For example, let output splits number, test size and split 1, elements: 1, 301. + int numSplits = dataset->getNumSplits(); + printf("splits number: %u\n", numSplits); + printf("test size: %u\n", (unsigned int)dataset->getTest().size()); + + FR_lfwObj *example = static_cast(dataset->getTest()[0].get()); + printf("first test, first image: %s\n", example->image1.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(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; } diff --git a/modules/datasetstools/samples/gr_chalearn.cpp b/modules/datasetstools/samples/gr_chalearn.cpp index c9a868606..fa972667e 100644 --- a/modules/datasetstools/samples/gr_chalearn.cpp +++ b/modules/datasetstools/samples/gr_chalearn.cpp @@ -65,15 +65,17 @@ int main(int argc, char *argv[]) return -1; } - GR_chalearn dataset(path); + Ptr dataset = GR_chalearn::create(); + dataset->load(path); // *************** // dataset contains information for each sample. // For example, let output dataset size and first element. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - GR_chalearnObj *example = static_cast(dataset.train[0].get()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("validation size: %u\n", (unsigned int)dataset->getValidation().size()); + GR_chalearnObj *example = static_cast(dataset->getTrain()[0].get()); 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("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); diff --git a/modules/datasetstools/samples/gr_skig.cpp b/modules/datasetstools/samples/gr_skig.cpp index eb8e1b976..9eb099049 100644 --- a/modules/datasetstools/samples/gr_skig.cpp +++ b/modules/datasetstools/samples/gr_skig.cpp @@ -66,13 +66,14 @@ int main(int argc, char *argv[]) return -1; } - GR_skig dataset(path); + Ptr dataset = GR_skig::create(); + dataset->load(path); // *************** // dataset contains pair of rgb\dep images // For example, let output train size and second element. - GR_skigObj *example = static_cast(dataset.train[1].get()); - printf("train size: %u\n", (unsigned int)dataset.train.size()); + GR_skigObj *example = static_cast(dataset->getTrain()[1].get()); + 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("person: %u, backgroud: %u, illumination: %u, pose: %u, actionType: %u\n", example->person, example->background, example->illumination, example->pose, example->type); diff --git a/modules/datasetstools/samples/hpe_parse.cpp b/modules/datasetstools/samples/hpe_parse.cpp index 56b8ff031..b99ee189e 100644 --- a/modules/datasetstools/samples/hpe_parse.cpp +++ b/modules/datasetstools/samples/hpe_parse.cpp @@ -65,15 +65,16 @@ int main(int argc, char *argv[]) return -1; } - HPE_parse dataset(path); + Ptr dataset = HPE_parse::create(); + dataset->load(path); // *************** // dataset. train & test contain appropriate images // For example, let output their sizes and first elements. - printf("train size: %u\n", (unsigned int)dataset.train.size()); - printf("test size: %u\n", (unsigned int)dataset.test.size()); - HPE_parseObj *example1 = static_cast(dataset.train[0].get()); - HPE_parseObj *example2 = static_cast(dataset.test[0].get()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("test size: %u\n", (unsigned int)dataset->getTest().size()); + HPE_parseObj *example1 = static_cast(dataset->getTrain()[0].get()); + HPE_parseObj *example2 = static_cast(dataset->getTest()[0].get()); printf("first train image: %s\n", example1->name.c_str()); printf("first test image: %s\n", example2->name.c_str()); diff --git a/modules/datasetstools/samples/ir_affine.cpp b/modules/datasetstools/samples/ir_affine.cpp index 1101b86f6..06bc2f227 100644 --- a/modules/datasetstools/samples/ir_affine.cpp +++ b/modules/datasetstools/samples/ir_affine.cpp @@ -67,15 +67,16 @@ int main(int argc, char *argv[]) } // loading dataset - IR_affine dataset(path); + Ptr dataset = IR_affine::create(); + dataset->load(path); // *************** // dataset contains for each image in dataset it's matrix. // For example, let output the last element in dataset and it's matrix. // 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(dataset.train.back().get()); + IR_affineObj *example = static_cast(dataset->getTrain().back().get()); printf("image name: %s\n", example->imageName.c_str()); printf("matrix:\n"); for (int i=0; i<3; ++i) diff --git a/modules/datasetstools/samples/ir_robot.cpp b/modules/datasetstools/samples/ir_robot.cpp index bdd4d27f8..b06eb327b 100644 --- a/modules/datasetstools/samples/ir_robot.cpp +++ b/modules/datasetstools/samples/ir_robot.cpp @@ -65,19 +65,26 @@ int main(int argc, char *argv[]) return -1; } - IR_robot dataset(path); + Ptr dataset = IR_robot::create(); + dataset->load(path); // *************** // dataset contains object with name and its images. // For example, let output last element and dataset size. - IR_robotObj *example = static_cast(dataset.train.back().get()); - printf("last dataset object:\n%s\n", example->name.c_str()); + IR_robotObj *example = static_cast(dataset->getTrain().back().get()); + 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 + "/"); - for (vector::iterator it=example->images.begin(); it!=example->images.end(); ++it) + + for (vector::iterator itP=example->pos.begin(); itP!=example->pos.end(); ++itP) { - printf("%s\n", (currPath+(*it)).c_str()); + for (vector::iterator it=itP->images.begin(); it!=itP->images.end(); ++it) + { + printf("%s\n", (currPath+(*it)).c_str()); + } } - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); + printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); return 0; } diff --git a/modules/datasetstools/samples/is_bsds.cpp b/modules/datasetstools/samples/is_bsds.cpp index dfa5f8a9e..4c27954a5 100644 --- a/modules/datasetstools/samples/is_bsds.cpp +++ b/modules/datasetstools/samples/is_bsds.cpp @@ -65,7 +65,8 @@ int main(int argc, char *argv[]) return -1; } - IS_bsds dataset(path); + Ptr dataset = IS_bsds::create(); + dataset->load(path); // TODO: read human/ folder for evaluation @@ -73,13 +74,13 @@ int main(int argc, char *argv[]) // dataset. train & test contain names of appropriate images. // For example, let output full path & name for first train and test images. // And sets size. - printf("train size: %u\n", (unsigned int)dataset.train.size()); - printf("test size: %u\n", (unsigned int)dataset.test.size()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("test size: %u\n", (unsigned int)dataset->getTest().size()); - IS_bsdsObj *example1 = static_cast(dataset.train[0].get()); + IS_bsdsObj *example1 = static_cast(dataset->getTrain()[0].get()); string fullPath(path + "images/train/" + example1->name + ".jpg"); printf("first train image: %s\n", fullPath.c_str()); - IS_bsdsObj *example2 = static_cast(dataset.test[0].get()); + IS_bsdsObj *example2 = static_cast(dataset->getTest()[0].get()); fullPath = path + "images/test/" + example2->name + ".jpg"; printf("first test image: %s\n", fullPath.c_str()); diff --git a/modules/datasetstools/samples/is_weizmann.cpp b/modules/datasetstools/samples/is_weizmann.cpp index 255e77a38..6ee152fa1 100644 --- a/modules/datasetstools/samples/is_weizmann.cpp +++ b/modules/datasetstools/samples/is_weizmann.cpp @@ -65,13 +65,14 @@ int main(int argc, char *argv[]) return -1; } - IS_weizmann dataset(path); + Ptr dataset = IS_weizmann::create(); + dataset->load(path); // *************** // dataset contains all information for each image. // For example, let output dataset size and first object. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - IS_weizmannObj *example = static_cast(dataset.train[0].get()); + printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + IS_weizmannObj *example = static_cast(dataset->getTrain()[0].get()); 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()); diff --git a/modules/datasetstools/samples/msm_epfl.cpp b/modules/datasetstools/samples/msm_epfl.cpp index b8d76c767..f80f340b5 100644 --- a/modules/datasetstools/samples/msm_epfl.cpp +++ b/modules/datasetstools/samples/msm_epfl.cpp @@ -65,35 +65,70 @@ int main(int argc, char *argv[]) return -1; } - MSM_epfl dataset(path); + Ptr dataset = MSM_epfl::create(); + dataset->load(path); // *************** // dataset contains all information for each image. // For example, let output dataset size and first object. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - MSM_epflObj *example = static_cast(dataset.train[0].get()); + printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + MSM_epflObj *example = static_cast(dataset->getTrain()[0].get()); printf("first image:\nname: %s\n", example->imageName.c_str()); - printf("bounding:\n"); - for (vector::iterator it=example->bounding.begin(); it!=example->bounding.end(); ++it) + printf("\nbounding:\n"); + 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"); - for (vector::iterator it=example->camera.begin(); it!=example->camera.end(); ++it) + printf("\ncamera:\n"); + for (int i=0; i<3; ++i) { - printf("%f ", *it); + for (int j=0; j<3; ++j) + { + printf("%f ", example->camera.mat1(i, j)); + } + printf("\n"); } printf("\n"); - printf("P:\n"); - for (vector::iterator it=example->p.begin(); it!=example->p.end(); ++it) + for (int i=0; i<3; ++i) + { + printf("%f ", example->camera.mat2[i]); + } + printf("\n\n"); + + for (int i=0; i<3; ++i) { - printf("%f ", *it); + for (int j=0; j<3; ++j) + { + printf("%f ", example->camera.mat3(i, j)); + } + printf("\n"); } printf("\n"); + 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; } diff --git a/modules/datasetstools/samples/msm_middlebury.cpp b/modules/datasetstools/samples/msm_middlebury.cpp index 97eed4e70..20f030e06 100644 --- a/modules/datasetstools/samples/msm_middlebury.cpp +++ b/modules/datasetstools/samples/msm_middlebury.cpp @@ -65,20 +65,21 @@ int main(int argc, char *argv[]) return -1; } - MSM_middlebury dataset(path); + Ptr dataset = MSM_middlebury::create(); + dataset->load(path); // *************** // dataset contains camera parameters for each image. // For example, let output number of elements and last element. - printf("images number: %u\n", (unsigned int)dataset.train.size()); - MSM_middleburyObj *example = static_cast(dataset.train.back().get()); + printf("images number: %u\n", (unsigned int)dataset->getTrain().size()); + MSM_middleburyObj *example = static_cast(dataset->getTrain().back().get()); printf("last image name: %s\n", (path + example->imageName).c_str()); printf("K:\n"); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { - printf("%f ", example->k[i][j]); + printf("%f ", example->k(i, j)); } printf("\n"); } @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) { for (int j=0; j<3; ++j) { - printf("%f ", example->r[i][j]); + printf("%f ", example->r(i, j)); } printf("\n"); } diff --git a/modules/datasetstools/samples/or_imagenet.cpp b/modules/datasetstools/samples/or_imagenet.cpp index 94e779d7f..99f13123b 100644 --- a/modules/datasetstools/samples/or_imagenet.cpp +++ b/modules/datasetstools/samples/or_imagenet.cpp @@ -67,14 +67,14 @@ int main(int argc, char *argv[]) return -1; } - OR_imagenet dataset(path); + Ptr dataset = OR_imagenet::create(); + dataset->load(path); // *************** // dataset contains for each object its id & image url. // For example, let output dataset size and first object. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - printf("wnids number: %u\n", (unsigned int)dataset.wnids.size()); - OR_imagenetObj *example = static_cast(dataset.train[0].get()); + printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + OR_imagenetObj *example = static_cast(dataset->getTrain()[0].get()); printf("first object url: %s\n", example->imageUrl.c_str()); printf("first object wnid: %s\n", example->wnid.c_str()); printf("first object id2: %u\n", example->id2); diff --git a/modules/datasetstools/samples/or_mnist.cpp b/modules/datasetstools/samples/or_mnist.cpp new file mode 100644 index 000000000..cb776ba43 --- /dev/null +++ b/modules/datasetstools/samples/or_mnist.cpp @@ -0,0 +1,89 @@ +/*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 +#include + +#include + +#include +#include + +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("path")); + if (parser.has("help") || path=="true") + { + parser.printMessage(); + return -1; + } + + Ptr 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(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(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; +} diff --git a/modules/datasetstools/samples/or_sun.cpp b/modules/datasetstools/samples/or_sun.cpp index 447233a29..0804d8936 100644 --- a/modules/datasetstools/samples/or_sun.cpp +++ b/modules/datasetstools/samples/or_sun.cpp @@ -65,13 +65,14 @@ int main(int argc, char *argv[]) return -1; } - OR_sun dataset(path); + Ptr dataset = OR_sun::create(); + dataset->load(path); // *************** // dataset contains for each object its images. // For example, let output dataset size and last object. - printf("dataset size: %u\n", (unsigned int)dataset.train.size()); - OR_sunObj *example = static_cast(dataset.train.back().get()); + printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + OR_sunObj *example = static_cast(dataset->getTrain().back().get()); printf("last object name: %s\n", example->name.c_str()); printf("last object images number: %u\n", (unsigned int)example->imageNames.size()); vector &imageNames = example->imageNames; diff --git a/modules/datasetstools/samples/slam_kitti.cpp b/modules/datasetstools/samples/slam_kitti.cpp index d82e61620..c2112208e 100644 --- a/modules/datasetstools/samples/slam_kitti.cpp +++ b/modules/datasetstools/samples/slam_kitti.cpp @@ -65,14 +65,15 @@ int main(int argc, char *argv[]) return -1; } - SLAM_kitti dataset(path); + Ptr dataset = SLAM_kitti::create(); + dataset->load(path); // *************** // dataset contains sequence with name and its data. // 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(dataset.train[0].get()); + SLAM_kittiObj *example = static_cast(dataset->getTrain()[0].get()); printf("first dataset sequence:\n%s\n", example->name.c_str()); /*string pathVelodyne(path + "sequences/" + example->name + "/velodyne/"); diff --git a/modules/datasetstools/samples/slam_tumindoor.cpp b/modules/datasetstools/samples/slam_tumindoor.cpp index c93060aa2..2ba504b66 100644 --- a/modules/datasetstools/samples/slam_tumindoor.cpp +++ b/modules/datasetstools/samples/slam_tumindoor.cpp @@ -65,14 +65,15 @@ int main(int argc, char *argv[]) return -1; } - SLAM_tumindoor dataset(path); + Ptr dataset = SLAM_tumindoor::create(); + dataset->load(path); // *************** // dataset contains image and its information. // 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(dataset.train[0].get()); + SLAM_tumindoorObj *example = static_cast(dataset->getTrain()[0].get()); printf("first image:\ntype: %u\n", example->type); string imagePath(path); @@ -85,12 +86,12 @@ int main(int argc, char *argv[]) } 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 j=0; j<4; ++j) { - printf("%f ", example->transformMat[i][j]); + printf("%f ", example->transformMat(i, j)); } printf("\n"); } diff --git a/modules/datasetstools/samples/tr_chars.cpp b/modules/datasetstools/samples/tr_chars.cpp index e2c5a3506..0dd28d6f7 100644 --- a/modules/datasetstools/samples/tr_chars.cpp +++ b/modules/datasetstools/samples/tr_chars.cpp @@ -66,34 +66,32 @@ int main(int argc, char *argv[]) return -1; } - vector dataset; - do - { - 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 + Ptr dataset = TR_chars::create(); + dataset->load(path); // *************** // 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. // 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 > &currTrain = dataset.back().train; - vector< Ptr > &currTest = dataset.back().test; + vector< Ptr > &currTrain = dataset->getTrain(numSplits-1); + vector< Ptr > &currTest = dataset->getTest(numSplits-1); + vector< Ptr > &currValidation = dataset->getValidation(numSplits-1); printf("train size: %u\n", (unsigned int)currTrain.size()); printf("test size: %u\n", (unsigned int)currTest.size()); + printf("validation size: %u\n", (unsigned int)currValidation.size()); - TR_charsObj *example1 = static_cast(currTrain[0].get()); - TR_charsObj *example2 = static_cast(currTest[0].get()); - printf("first train element:\nname: %s\n", example1->imgName.c_str()); - printf("label: %u\n", example1->label); - printf("first test element:\nname: %s\n", example2->imgName.c_str()); - printf("label: %u\n", example2->label); + TR_charsObj *exampleTrain = static_cast(currTrain[0].get()); + TR_charsObj *exampleTest = static_cast(currTest[0].get()); + TR_charsObj *exampleValidation = static_cast(currValidation[0].get()); + printf("first train element:\nname: %s\n", exampleTrain->imgName.c_str()); + printf("label: %u\n", exampleTrain->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; } diff --git a/modules/datasetstools/samples/tr_svt.cpp b/modules/datasetstools/samples/tr_svt.cpp index 563db00ff..9dc05303e 100644 --- a/modules/datasetstools/samples/tr_svt.cpp +++ b/modules/datasetstools/samples/tr_svt.cpp @@ -67,16 +67,17 @@ int main(int argc, char *argv[]) } // loading train & test images description - TR_svt dataset(path); + Ptr dataset = TR_svt::create(); + dataset->load(path); // *************** // dataset. train & test contains images description. // For example, let output the last element in train set and it's description. // And their sizes. - printf("train size: %u\n", (unsigned int)dataset.train.size()); - printf("test size: %u\n", (unsigned int)dataset.test.size()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("test size: %u\n", (unsigned int)dataset->getTest().size()); - TR_svtObj *example = static_cast(dataset.train.back().get()); + TR_svtObj *example = static_cast(dataset->getTrain().back().get()); printf("last element:\nfile name: %s", example->fileName.c_str()); printf("\nlex: "); for (vector::iterator it=example->lex.begin(); it!=example->lex.end(); ++it) diff --git a/modules/datasetstools/src/ar_hmdb.cpp b/modules/datasetstools/src/ar_hmdb.cpp index 1df15eced..d30d48507 100644 --- a/modules/datasetstools/src/ar_hmdb.cpp +++ b/modules/datasetstools/src/ar_hmdb.cpp @@ -49,7 +49,24 @@ namespace datasetstools using namespace std; -void AR_hmdb::loadAction(const string &fileName, vector &train_, vector &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 &train_, vector &test_); +}; + +void AR_hmdbImp::loadAction(const string &fileName, vector &train_, vector &test_) { ifstream infile(fileName.c_str()); string video, label; @@ -66,17 +83,25 @@ void AR_hmdb::loadAction(const string &fileName, vector &train_, vector< } } -AR_hmdb::AR_hmdb(const string &path, int number) +/*AR_hmdbImp::AR_hmdbImp(const string &path, int 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] if (number<0 || number>2) @@ -84,6 +109,10 @@ void AR_hmdb::loadDataset(const string &path, int number) return; } + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string pathDataset(path + "hmdb51_org/"); string pathSplit(path + "testTrainMulti_7030_splits/"); @@ -96,8 +125,8 @@ void AR_hmdb::loadDataset(const string &path, int number) currTrain->name = *it; currTest->name = *it; - train.push_back(currTrain); - test.push_back(currTest); + train.back().push_back(currTrain); + test.back().push_back(currTest); char tmp[2]; sprintf(tmp, "%u", number+1); @@ -106,5 +135,10 @@ void AR_hmdb::loadDataset(const string &path, int number) } } +Ptr AR_hmdb::create() +{ + return Ptr(new AR_hmdbImp); +} + } } diff --git a/modules/datasetstools/src/ar_sports.cpp b/modules/datasetstools/src/ar_sports.cpp index e8533ccff..0f4b4cf58 100644 --- a/modules/datasetstools/src/ar_sports.cpp +++ b/modules/datasetstools/src/ar_sports.cpp @@ -49,7 +49,22 @@ namespace datasetstools using namespace std; -void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr > &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 > &dataset_); +}; + +void AR_sportsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) { ifstream infile(fileName.c_str()); string videoUrl, labels; @@ -69,31 +84,35 @@ void AR_sports::loadDatasetPart(const string &fileName, vector< Ptr > &d } } -AR_sports::AR_sports(const string &path) +/*AR_sportsImp::AR_sportsImp(const string &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); } -void AR_sports::loadDataset(const string &path) +void AR_sportsImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string trainPath(path + "original/train_partition.txt"); string testPath(path + "original/test_partition.txt"); // loading train video urls & labels - loadDatasetPart(trainPath, train); + loadDatasetPart(trainPath, train.back()); // loading test video urls & labels - loadDatasetPart(testPath, test); + loadDatasetPart(testPath, test.back()); +} + +Ptr AR_sports::create() +{ + return Ptr(new AR_sportsImp); } } diff --git a/modules/datasetstools/src/dataset.cpp b/modules/datasetstools/src/dataset.cpp new file mode 100644 index 000000000..9473f2aa3 --- /dev/null +++ b/modules/datasetstools/src/dataset.cpp @@ -0,0 +1,89 @@ +/*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 >& Dataset::getTrain(int splitNum) +{ + if (splitNum >= (int)train.size()) + { + return empty; + } + + return train[splitNum]; +} + +vector< Ptr >& Dataset::getTest(int splitNum) +{ + if (splitNum >= (int)test.size()) + { + return empty; + } + + return test[splitNum]; +} + +vector< Ptr >& Dataset::getValidation(int splitNum) +{ + if (splitNum >= (int)validation.size()) + { + return empty; + } + + return validation[splitNum]; +} + +int Dataset::getNumSplits() const +{ + return (int)train.size(); +} + +} +} + diff --git a/modules/datasetstools/src/fr_lfw.cpp b/modules/datasetstools/src/fr_lfw.cpp index 0e736fd5d..420bd9143 100644 --- a/modules/datasetstools/src/fr_lfw.cpp +++ b/modules/datasetstools/src/fr_lfw.cpp @@ -42,6 +42,8 @@ #include "opencv2/datasetstools/fr_lfw.hpp" #include "precomp.hpp" +#include + namespace cv { namespace datasetstools @@ -49,40 +51,102 @@ namespace datasetstools 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 > faces; +}; + +/*FR_lfwImp::FR_lfwImp(const string &path) { - if (number!=0) - { - return; - } + loadDataset(path); +}*/ +void FR_lfwImp::load(const string &path) +{ loadDataset(path); } -void FR_lfw::loadDataset(const string &path) +void FR_lfwImp::loadDataset(const string &path) { vector fileNames; getDirList(path, fileNames); for (vector::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) { - Ptr curr(new FR_lfwObj); - curr->name = *it; + if ("pairs.txt" == *it) + { + continue; + } + + string &name = *it; + vector images; - string pathFace(path + curr->name + "/"); + string pathFace(path + name + "/"); vector faceNames; getDirList(pathFace, faceNames); for (vector::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 >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + } + + vector elems; + split(line, elems, '\t'); + + Ptr 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::create() +{ + return Ptr(new FR_lfwImp); } } diff --git a/modules/datasetstools/src/gr_chalearn.cpp b/modules/datasetstools/src/gr_chalearn.cpp index 96003ab58..b9380193b 100644 --- a/modules/datasetstools/src/gr_chalearn.cpp +++ b/modules/datasetstools/src/gr_chalearn.cpp @@ -49,22 +49,32 @@ namespace datasetstools 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); -void GR_chalearn::load(const string &path, int number) +private: + void loadDataset(const string &path); + + void loadDatasetPart(const string &path, vector< Ptr > &dataset_, bool loadLabels); +}; + +/*GR_chalearnImp::GR_chalearnImp(const string &path) { - if (number!=0) - { - return; - } + loadDataset(path); +}*/ +void GR_chalearnImp::load(const string &path) +{ loadDataset(path); } -void GR_chalearn::loadDataset(const string &path) +void GR_chalearnImp::loadDatasetPart(const string &path, vector< Ptr > &dataset_, bool loadLabels) { vector fileNames; getDirList(path, fileNames); @@ -88,19 +98,22 @@ void GR_chalearn::loadDataset(const string &path) curr->depth = atoi(elems[2].c_str()); // loading ground truth - string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv"); - ifstream infileGroundTruth(fileGroundTruth.c_str()); - while (getline(infileGroundTruth, line)) + if (loadLabels) { - vector elems2; - split(line, elems2, ','); + string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv"); + ifstream infileGroundTruth(fileGroundTruth.c_str()); + while (getline(infileGroundTruth, line)) + { + vector elems2; + split(line, elems2, ','); - groundTruth currGroundTruth; - currGroundTruth.gestureID = atoi(elems2[0].c_str()); - currGroundTruth.initialFrame = atoi(elems2[1].c_str()); - currGroundTruth.lastFrame = atoi(elems2[2].c_str()); + groundTruth currGroundTruth; + currGroundTruth.gestureID = atoi(elems2[0].c_str()); + currGroundTruth.initialFrame = atoi(elems2[1].c_str()); + currGroundTruth.lastFrame = atoi(elems2[2].c_str()); - curr->groundTruths.push_back(currGroundTruth); + curr->groundTruths.push_back(currGroundTruth); + } } // loading skeleton @@ -129,9 +142,28 @@ void GR_chalearn::loadDataset(const string &path) 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 >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + + 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::create() +{ + return Ptr(new GR_chalearnImp); +} + } } diff --git a/modules/datasetstools/src/gr_skig.cpp b/modules/datasetstools/src/gr_skig.cpp index 0f32b9fde..fe783fd37 100644 --- a/modules/datasetstools/src/gr_skig.cpp +++ b/modules/datasetstools/src/gr_skig.cpp @@ -51,23 +51,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void GR_skigImp::load(const string &path) +{ loadDataset(path); } -void GR_skig::loadDataset(const string &path) +void GR_skigImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + for (unsigned int i=1; i<=6; ++i) { char number[2]; @@ -87,21 +99,36 @@ void GR_skig::loadDataset(const string &path) curr->dep[0] = 'K'; curr->dep = pathDatasetDep + curr->dep; - size_t pos = file.find("person_"); // TODO: check ::npos - curr->person = (unsigned char)atoi( file.substr(pos+strlen("person_"), 1).c_str() ); - pos = file.find("backgroud_"); - curr->background = (backgroundType)atoi( file.substr(pos+strlen("backgroud_"), 1).c_str() ); - pos = file.find("illumination_"); - curr->illumination = (illuminationType)atoi( file.substr(pos+strlen("illumination_"), 1).c_str() ); - pos = file.find("pose_"); - curr->pose = (poseType)atoi( file.substr(pos+strlen("pose_"), 1).c_str() ); - pos = file.find("actionType_"); - curr->type = (actionType)atoi( file.substr(pos+strlen("actionType_"), 2).c_str() ); - - train.push_back(curr); + size_t posPerson = file.find("person_"); + size_t posBackground = file.find("backgroud_"); + size_t posIllumination = file.find("illumination_"); + size_t posPose = file.find("pose_"); + size_t posType = file.find("actionType_"); + if (string::npos != posPerson && + string::npos != posBackground && + string::npos != posIllumination && + string::npos != posPose && + string::npos != posType) + { + 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::create() +{ + return Ptr(new GR_skigImp); +} + } } diff --git a/modules/datasetstools/src/hpe_parse.cpp b/modules/datasetstools/src/hpe_parse.cpp index f0ee8fc0c..ea835fdc1 100644 --- a/modules/datasetstools/src/hpe_parse.cpp +++ b/modules/datasetstools/src/hpe_parse.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void HPE_parseImp::load(const string &path) +{ loadDataset(path); } -void HPE_parse::loadDataset(const string &path) +void HPE_parseImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + unsigned int i=0; vector fileNames; getDirList(path, fileNames); @@ -84,15 +96,20 @@ void HPE_parse::loadDataset(const string &path) if (i<100) { - train.push_back(curr); + train.back().push_back(curr); } else { - test.push_back(curr); + test.back().push_back(curr); } ++i; } } } +Ptr HPE_parse::create() +{ + return Ptr(new HPE_parseImp); +} + } } diff --git a/modules/datasetstools/src/ir_affine.cpp b/modules/datasetstools/src/ir_affine.cpp index 5ad3dac2c..3373ecd15 100644 --- a/modules/datasetstools/src/ir_affine.cpp +++ b/modules/datasetstools/src/ir_affine.cpp @@ -49,30 +49,56 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void IR_affineImp::load(const string &path) +{ loadDataset(path); } -void IR_affine::loadDataset(const string &path) +void IR_affineImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + + // detect image extension + string ext; + vector fileNames; + getDirList(path, fileNames); + for (vector::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) { Ptr curr(new IR_affineObj); char tmp[2]; sprintf(tmp, "%u", i); - curr->imageName = path + "img" + tmp + ".ppm"; + curr->imageName = path + "img" + tmp + ext; if (i>1) { @@ -87,9 +113,14 @@ void IR_affine::loadDataset(const string &path) } } - train.push_back(curr); + train.back().push_back(curr); } } +Ptr IR_affine::create() +{ + return Ptr(new IR_affineImp); +} + } } diff --git a/modules/datasetstools/src/ir_robot.cpp b/modules/datasetstools/src/ir_robot.cpp index 65c17b73c..e9c0678f5 100644 --- a/modules/datasetstools/src/ir_robot.cpp +++ b/modules/datasetstools/src/ir_robot.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void IR_robotImp::load(const string &path) +{ loadDataset(path); } -void IR_robot::loadDataset(const string &path) +void IR_robotImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + vector fileNames; getDirList(path, fileNames); for (vector::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) @@ -76,14 +88,30 @@ void IR_robot::loadDataset(const string &path) string pathScene(path + curr->name + "/"); vector sceneNames; getDirList(pathScene, sceneNames); + int currImageNum = 0; for (vector::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::create() +{ + return Ptr(new IR_robotImp); +} + } } diff --git a/modules/datasetstools/src/is_bsds.cpp b/modules/datasetstools/src/is_bsds.cpp index 270fcc8d3..ebc397e30 100644 --- a/modules/datasetstools/src/is_bsds.cpp +++ b/modules/datasetstools/src/is_bsds.cpp @@ -49,7 +49,22 @@ namespace datasetstools using namespace std; -void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr > &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 > &dataset_); +}; + +void IS_bsdsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) { ifstream infile(fileName.c_str()); string imageName; @@ -61,31 +76,35 @@ void IS_bsds::loadDatasetPart(const string &fileName, vector< Ptr > &dat } } -IS_bsds::IS_bsds(const string &path) +/*IS_bsdsImp::IS_bsdsImp(const string &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); } -void IS_bsds::loadDataset(const string &path) +void IS_bsdsImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string trainName(path + "iids_train.txt"); string testName(path + "iids_test.txt"); // loading train - loadDatasetPart(trainName, train); + loadDatasetPart(trainName, train.back()); // loading test - loadDatasetPart(testName, test); + loadDatasetPart(testName, test.back()); +} + +Ptr IS_bsds::create() +{ + return Ptr(new IS_bsdsImp); } } diff --git a/modules/datasetstools/src/is_weizmann.cpp b/modules/datasetstools/src/is_weizmann.cpp index a1d6b332f..094521080 100644 --- a/modules/datasetstools/src/is_weizmann.cpp +++ b/modules/datasetstools/src/is_weizmann.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void IS_weizmannImp::load(const string &path) +{ loadDataset(path); } -void IS_weizmann::loadDataset(const string &path) +void IS_weizmannImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + vector fileNames; getDirList(path, fileNames); for (vector::iterator it=fileNames.begin(); it!=fileNames.end(); ++it) @@ -80,10 +92,15 @@ void IS_weizmann::loadDataset(const string &path) curr->humanSeg = imageName + "human_seg/"; - train.push_back(curr); + train.back().push_back(curr); } } } +Ptr IS_weizmann::create() +{ + return Ptr(new IS_weizmannImp); +} + } } diff --git a/modules/datasetstools/src/msm_epfl.cpp b/modules/datasetstools/src/msm_epfl.cpp index 195d30d02..220691e0c 100644 --- a/modules/datasetstools/src/msm_epfl.cpp +++ b/modules/datasetstools/src/msm_epfl.cpp @@ -49,33 +49,35 @@ namespace datasetstools using namespace std; -void MSM_epfl::readFileDouble(const string &fileName, vector &out) +class CV_EXPORTS MSM_epflImp : public MSM_epfl { - ifstream infile(fileName.c_str()); - double val; - while (infile >> val) - { - out.push_back(val); - } -} +public: + MSM_epflImp() {} + //MSM_epflImp(const string &path); + virtual ~MSM_epflImp() {} + + 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); -} +}*/ -void MSM_epfl::load(const string &path, int number) +void MSM_epflImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(path); } -void MSM_epfl::loadDataset(const string &path) +void MSM_epflImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string pathBounding(path + "bounding/"); string pathCamera(path + "camera/"); string pathP(path + "P/"); @@ -88,13 +90,67 @@ void MSM_epfl::loadDataset(const string &path) Ptr curr(new MSM_epflObj); curr->imageName = *it; - readFileDouble(string(pathBounding + curr->imageName + ".bounding"), curr->bounding); - readFileDouble(string(pathCamera + curr->imageName + ".camera"), curr->camera); - readFileDouble(string(pathP + curr->imageName + ".P"), curr->p); + // load boundary + string fileBounding(pathBounding + curr->imageName + ".bounding"); + ifstream infile(fileBounding.c_str()); + for (int k=0; k<2; ++k) + { + for (int j=0; j<3; ++j) + { + infile >> curr->bounding(k, j); + } + } - train.push_back(curr); + // load camera parameters + string fileCamera(pathCamera + curr->imageName + ".camera"); + ifstream infileCamera(fileCamera.c_str()); + for (int i=0; i<3; ++i) + { + for (int j=0; j<3; ++j) + { + infileCamera >> curr->camera.mat1(i, j); + } + } + + for (int i=0; i<3; ++i) + { + infileCamera >> curr->camera.mat2[i]; + } + + for (int i=0; i<3; ++i) + { + for (int j=0; j<3; ++j) + { + infileCamera >> curr->camera.mat3(i, j); + } + } + + for (int i=0; i<3; ++i) + { + infileCamera >> curr->camera.mat4[i]; + } + + infileCamera >> curr->camera.imageWidth >> curr->camera.imageHeight; + + // load P + string fileP(pathP + curr->imageName + ".P"); + ifstream infileP(fileP.c_str()); + for (int k=0; k<3; ++k) + { + for (int j=0; j<4; ++j) + { + infileP >> curr->p(k, j); + } + } + + train.back().push_back(curr); } } +Ptr MSM_epfl::create() +{ + return Ptr(new MSM_epflImp); +} + } } diff --git a/modules/datasetstools/src/msm_middlebury.cpp b/modules/datasetstools/src/msm_middlebury.cpp index a94f84fcb..e65b1330f 100644 --- a/modules/datasetstools/src/msm_middlebury.cpp +++ b/modules/datasetstools/src/msm_middlebury.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void MSM_middleburyImp::load(const string &path) +{ loadDataset(path); } -void MSM_middlebury::loadDataset(const string &path) +void MSM_middleburyImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string name(path.substr(0, path.length()-1)); size_t start = name.rfind('/'); name = name.substr(start+1, name.length()-start); @@ -85,14 +97,14 @@ void MSM_middlebury::loadDataset(const string &path) { 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 j=0; j<3; ++j) { - infile >> curr->r[i][j]; + infile >> curr->r(i, j); } } for (int i=0; i<3; ++i) @@ -100,9 +112,14 @@ void MSM_middlebury::loadDataset(const string &path) infile >> curr->t[i]; } - train.push_back(curr); + train.back().push_back(curr); } } +Ptr MSM_middlebury::create() +{ + return Ptr(new MSM_middleburyImp); +} + } } diff --git a/modules/datasetstools/src/or_imagenet.cpp b/modules/datasetstools/src/or_imagenet.cpp index 740790c7f..dc5986a4d 100644 --- a/modules/datasetstools/src/or_imagenet.cpp +++ b/modules/datasetstools/src/or_imagenet.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void OR_imagenetImp::load(const string &path) +{ loadDataset(path); } -void OR_imagenet::loadDataset(const string &path) +void OR_imagenetImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + ifstream infile((path + "fall11_urls.txt").c_str()); string line; while (getline(infile, line)) @@ -83,11 +95,14 @@ void OR_imagenet::loadDataset(const string &path) curr->wnid = elems[0]; curr->id2 = atoi(elems[1].c_str()); - wnids.insert(curr->wnid); - - train.push_back(curr); + train.back().push_back(curr); } } +Ptr OR_imagenet::create() +{ + return Ptr(new OR_imagenetImp); +} + } } diff --git a/modules/datasetstools/src/or_mnist.cpp b/modules/datasetstools/src/or_mnist.cpp new file mode 100644 index 000000000..5fe312213 --- /dev/null +++ b/modules/datasetstools/src/or_mnist.cpp @@ -0,0 +1,142 @@ +/*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 > &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 > &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 curr(new OR_mnistObj); + curr->label = labels[i]; + + curr->image = Mat(28, 28, CV_8U); + unsigned int imageIdx = i*imageSize; + for (int j=0; jimage.rows; ++j) + { + char *im = curr->image.ptr(j); + for (int k=0; kimage.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 >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + + 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::create() +{ + return Ptr(new OR_mnistImp); +} + +} +} diff --git a/modules/datasetstools/src/or_sun.cpp b/modules/datasetstools/src/or_sun.cpp index 7732c4cc9..3a3492da5 100644 --- a/modules/datasetstools/src/or_sun.cpp +++ b/modules/datasetstools/src/or_sun.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void OR_sunImp::load(const string &path) +{ loadDataset(path); } -void OR_sun::loadDataset(const string &path) +void OR_sunImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string classNameFile(path + "ClassName.txt"); ifstream infile(classNameFile.c_str()); string line; @@ -82,9 +94,14 @@ void OR_sun::loadDataset(const string &path) curr->imageNames.push_back(*it); } - train.push_back(curr); + train.back().push_back(curr); } } +Ptr OR_sun::create() +{ + return Ptr(new OR_sunImp); +} + } } diff --git a/modules/datasetstools/src/slam_kitti.cpp b/modules/datasetstools/src/slam_kitti.cpp index d659720fe..697889fd3 100644 --- a/modules/datasetstools/src/slam_kitti.cpp +++ b/modules/datasetstools/src/slam_kitti.cpp @@ -49,23 +49,35 @@ namespace datasetstools 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) - { - return; - } + loadDataset(path); +}*/ +void SLAM_kittiImp::load(const string &path) +{ loadDataset(path); } -void SLAM_kitti::loadDataset(const string &path) +void SLAM_kittiImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string pathSequence(path + "sequences/"); vector fileNames; getDirList(pathSequence, fileNames); @@ -142,9 +154,14 @@ void SLAM_kitti::loadDataset(const string &path) curr->posesArray.push_back(p); } - train.push_back(curr); + train.back().push_back(curr); } } +Ptr SLAM_kitti::create() +{ + return Ptr(new SLAM_kittiImp); +} + } } diff --git a/modules/datasetstools/src/slam_tumindoor.cpp b/modules/datasetstools/src/slam_tumindoor.cpp index fc6033638..27712ebae 100644 --- a/modules/datasetstools/src/slam_tumindoor.cpp +++ b/modules/datasetstools/src/slam_tumindoor.cpp @@ -51,25 +51,63 @@ namespace datasetstools 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); } -void SLAM_tumindoor::load(const string &path, int number) +void SLAM_tumindoorImp::loadDataset(const string &path) { - if (number!=0) + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + + string infoPath(path + "info/"); + + // get info map name, .csv should be only one such file in folder + string csvName; + vector infoNames; + getDirList(infoPath, infoNames); + for (vector::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; } - loadDataset(path); -} - -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()); + ifstream infile((infoPath + csvName).c_str()); string line; while (getline(infile, line)) { @@ -95,13 +133,18 @@ void SLAM_tumindoor::loadDataset(const string &path) { 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::create() +{ + return Ptr(new SLAM_tumindoorImp); +} + } } diff --git a/modules/datasetstools/src/tr_chars.cpp b/modules/datasetstools/src/tr_chars.cpp index a229cc14d..0760f0f78 100644 --- a/modules/datasetstools/src/tr_chars.cpp +++ b/modules/datasetstools/src/tr_chars.cpp @@ -49,7 +49,28 @@ namespace datasetstools using namespace std; -void TR_chars::parseLine(const string &line, vector &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 &currSet, int number); + + inline void convert(vector &from, vector< Ptr > &to, vector &allLabels, vector &allNames); + + inline void parseSet(const string &line, const string &pattern, bool &flag, vector &set, int number); +}; + +void TR_charsImp::parseLine(const string &line, vector &currSet, int number) { vector elems; split(line, elems, ' '); @@ -65,33 +86,84 @@ void TR_chars::parseLine(const string &line, vector &currSet, int number) } } -TR_chars::TR_chars(const string &path, int number) +inline void TR_charsImp::convert(vector &from, vector< Ptr > &to, vector &allLabels, vector &allNames) { - loadDataset(path, number); + for (vector::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 curr(new TR_charsObj); + curr->imgName = allNames[*it]; + curr->label = allLabels[*it]; + to.push_back(curr); + } +} + +inline void TR_charsImp::parseSet(const string &line, const string &pattern, bool &flag, vector &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); + } } -void TR_chars::load(const string &path, int number) +/*TR_charsImp::TR_charsImp(const string &path, int 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 allLabels, trainSet, testSet; + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + + vector allLabels, trainSet, testSet, validationSet; vector allNames; ifstream infile((path + "list_English_Img.m").c_str()); 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)) { size_t pos = line.find("];"); - if (string::npos!=pos) + if (string::npos != pos) { labels = false; names = false; isTrain = false; isTest = false; + isValidation = false; } string slabels("list.ALLlabels = ["); @@ -109,7 +181,7 @@ void TR_chars::loadDataset(const string &path, int number) string snames("list.ALLnames = ["); pos = line.find(snames); - if (string::npos!=pos) + if (string::npos != pos) { names = true; size_t start = pos+snames.length(); @@ -122,66 +194,29 @@ void TR_chars::loadDataset(const string &path, int number) allNames.push_back(s); } - string strain("list.TRNind = ["); - pos = line.find(strain); - 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 trainStr("list.TRNind = ["); + parseSet(line, trainStr, isTrain, trainSet, number); - string stest("list.TSTind = ["); - pos = line.find(stest); - if (string::npos!=pos) - { - isTest = true; - string s(line.substr(pos+stest.length())); - parseLine(s, testSet, number); - } else - if (isTest) - { - parseLine(line, testSet, number); - } + string testStr("list.TSTind = ["); + parseSet(line, testStr, isTest, testSet, number); + + string validationStr("list.VALind = ["); + parseSet(line, validationStr, isValidation, validationSet, number); /*"list.classlabels = [" "list.classnames = [" "list.NUMclasses = 62;" - "list.VALind = [" // TODO: load validation "list.TXNind = ["*/ } - for (vector::iterator it=trainSet.begin(); it!=trainSet.end(); ++it) - { - if (*it>=(int)allNames.size() || *it>=(int)allLabels.size()) - { - printf("incorrect train index: %u\n", *it); - continue; - } - - Ptr curr(new TR_charsObj); - curr->imgName = allNames[*it]; - curr->label = allLabels[*it]; - train.push_back(curr); - } - - for (vector::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; - } + convert(trainSet, train.back(), allLabels, allNames); + convert(testSet, test.back(), allLabels, allNames); + convert(validationSet, validation.back(), allLabels, allNames); +} - Ptr curr(new TR_charsObj); - curr->imgName = allNames[*it]; - curr->label = allLabels[*it]; - test.push_back(curr); - } +Ptr TR_chars::create() +{ + return Ptr(new TR_charsImp); } } diff --git a/modules/datasetstools/src/tr_svt.cpp b/modules/datasetstools/src/tr_svt.cpp index c803c1c66..34d7fa908 100644 --- a/modules/datasetstools/src/tr_svt.cpp +++ b/modules/datasetstools/src/tr_svt.cpp @@ -52,7 +52,22 @@ namespace datasetstools using namespace std; using namespace tinyxml2; -void TR_svt::xmlParse(const string &set, vector< Ptr > &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 > &out); +}; + +void TR_svtImp::xmlParse(const string &set, vector< Ptr > &out) { XMLDocument doc; doc.LoadFile(set.c_str()); @@ -97,31 +112,35 @@ void TR_svt::xmlParse(const string &set, vector< Ptr > &out) } } -TR_svt::TR_svt(const string &path) +/*TR_svtImp::TR_svtImp(const string &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); } -void TR_svt::loadDataset(const string &path) +void TR_svtImp::loadDataset(const string &path) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + string trainXml(path + "train.xml"); string testXml(path + "test.xml"); // loading train images description - xmlParse(trainXml, train); + xmlParse(trainXml, train.back()); // loading test images description - xmlParse(testXml, test); + xmlParse(testXml, test.back()); +} + +Ptr TR_svt::create() +{ + return Ptr(new TR_svtImp); } }