From 7597e46ee3e014893d7bacb820a8d0fd5f3b160b Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Wed, 3 Sep 2014 17:13:05 +0400 Subject: [PATCH 1/8] interface-implementation pattern implemented --- .../include/opencv2/datasetstools/ar_hmdb.hpp | 11 ++----- .../opencv2/datasetstools/ar_sports.hpp | 11 ++----- .../include/opencv2/datasetstools/dataset.hpp | 4 +++ .../include/opencv2/datasetstools/fr_lfw.hpp | 9 ++---- .../opencv2/datasetstools/gr_chalearn.hpp | 9 ++---- .../include/opencv2/datasetstools/gr_skig.hpp | 9 ++---- .../opencv2/datasetstools/hpe_parse.hpp | 9 ++---- .../opencv2/datasetstools/ir_affine.hpp | 9 ++---- .../opencv2/datasetstools/ir_robot.hpp | 9 ++---- .../include/opencv2/datasetstools/is_bsds.hpp | 11 ++----- .../opencv2/datasetstools/is_weizmann.hpp | 9 ++---- .../opencv2/datasetstools/msm_epfl.hpp | 11 ++----- .../opencv2/datasetstools/msm_middlebury.hpp | 13 +++----- .../opencv2/datasetstools/or_imagenet.hpp | 12 ++------ .../include/opencv2/datasetstools/or_sun.hpp | 9 ++---- .../opencv2/datasetstools/slam_kitti.hpp | 9 ++---- .../opencv2/datasetstools/slam_tumindoor.hpp | 11 ++----- .../opencv2/datasetstools/tr_chars.hpp | 11 ++----- .../include/opencv2/datasetstools/tr_svt.hpp | 11 ++----- modules/datasetstools/samples/ar_hmdb.cpp | 7 +++-- modules/datasetstools/samples/ar_sports.cpp | 9 +++--- modules/datasetstools/samples/fr_lfw.cpp | 7 +++-- modules/datasetstools/samples/gr_chalearn.cpp | 7 +++-- modules/datasetstools/samples/gr_skig.cpp | 7 +++-- modules/datasetstools/samples/hpe_parse.cpp | 11 +++---- modules/datasetstools/samples/ir_affine.cpp | 7 +++-- modules/datasetstools/samples/ir_robot.cpp | 7 +++-- modules/datasetstools/samples/is_bsds.cpp | 11 +++---- modules/datasetstools/samples/is_weizmann.cpp | 7 +++-- modules/datasetstools/samples/msm_epfl.cpp | 7 +++-- .../datasetstools/samples/msm_middlebury.cpp | 11 +++---- modules/datasetstools/samples/or_imagenet.cpp | 8 ++--- modules/datasetstools/samples/or_sun.cpp | 7 +++-- modules/datasetstools/samples/slam_kitti.cpp | 7 +++-- .../datasetstools/samples/slam_tumindoor.cpp | 9 +++--- modules/datasetstools/samples/tr_chars.cpp | 12 ++++---- modules/datasetstools/samples/tr_svt.cpp | 9 +++--- modules/datasetstools/src/ar_hmdb.cpp | 30 +++++++++++++++---- modules/datasetstools/src/ar_sports.cpp | 30 +++++++++++++++---- modules/datasetstools/src/fr_lfw.cpp | 26 +++++++++++++--- modules/datasetstools/src/gr_chalearn.cpp | 26 +++++++++++++--- modules/datasetstools/src/gr_skig.cpp | 26 +++++++++++++--- modules/datasetstools/src/hpe_parse.cpp | 26 +++++++++++++--- modules/datasetstools/src/ir_affine.cpp | 26 +++++++++++++--- modules/datasetstools/src/ir_robot.cpp | 26 +++++++++++++--- modules/datasetstools/src/is_bsds.cpp | 30 +++++++++++++++---- modules/datasetstools/src/is_weizmann.cpp | 26 +++++++++++++--- modules/datasetstools/src/msm_epfl.cpp | 30 +++++++++++++++---- modules/datasetstools/src/msm_middlebury.cpp | 30 +++++++++++++++---- modules/datasetstools/src/or_imagenet.cpp | 28 +++++++++++++---- modules/datasetstools/src/or_sun.cpp | 26 +++++++++++++--- modules/datasetstools/src/slam_kitti.cpp | 26 +++++++++++++--- modules/datasetstools/src/slam_tumindoor.cpp | 28 +++++++++++++---- modules/datasetstools/src/tr_chars.cpp | 30 +++++++++++++++---- modules/datasetstools/src/tr_svt.cpp | 30 +++++++++++++++---- 55 files changed, 543 insertions(+), 294 deletions(-) diff --git a/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp b/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp index 4b35018568..a118586216 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, int number = 0) = 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 48361951e8..0b44d8ee32 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, int number = 0) = 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 78a76e0d0e..544719bbfb 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp @@ -64,6 +64,10 @@ class CV_EXPORTS Dataset virtual void load(const std::string &path, int number = 0) = 0; + std::vector< Ptr >& getTrain() { return train; } + std::vector< Ptr >& getTest() { return test; } + +protected: std::vector< Ptr > train; std::vector< Ptr > test; }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp index 372490c6da..a1866269b3 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp @@ -63,14 +63,9 @@ struct FR_lfwObj : public Object 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, int number = 0) = 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 f0b000b842..66e071a03a 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, int number = 0) = 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 800df1f835..abaad74821 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, int number = 0) = 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 9f21589a29..197e14c797 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, int number = 0) = 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 cfb82e1818..763514c76b 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, int number = 0) = 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 37b6ae224f..efb76ef4ff 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp @@ -68,14 +68,9 @@ struct IR_robotObj : public Object 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) = 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/is_bsds.hpp b/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp index b51956885d..40232b075a 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, int number = 0) = 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 6857ad3500..c8cb1f058a 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, int number = 0) = 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 eb1751cc93..22633667e6 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp @@ -63,16 +63,9 @@ struct MSM_epflObj : public Object 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) = 0; - virtual void load(const std::string &path, int number = 0); - -private: - void loadDataset(const std::string &path); - - void readFileDouble(const std::string &fileName, std::vector &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 4631ccaa32..c52ba41b95 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, int number = 0) = 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 83b1b36699..05fd1414eb 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, int number = 0) = 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_sun.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp index e151d515b3..f14aaea44d 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, int number = 0) = 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 3ca08e72ba..68fd3416ab 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, int number = 0) = 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 93b84b1f8b..a35e84ed6a 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, int number = 0) = 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 56bad3a1e3..3c61efe054 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, int number = 0) = 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 4f1358c4b1..57c50f791b 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, int number = 0) = 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 0c4c921dca..82c67da2a9 100644 --- a/modules/datasetstools/samples/ar_hmdb.cpp +++ b/modules/datasetstools/samples/ar_hmdb.cpp @@ -65,17 +65,18 @@ int main(int argc, char *argv[]) return -1; } - AR_hmdb dataset[3]; + Ptr dataset[3]; for (int i=0; i<3; ++i) { - dataset[i].load(path, i); + dataset[i] = AR_hmdb::create(); + dataset[i]->load(path, i); } // *************** // 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()); + AR_hmdbObj *example = static_cast(dataset[1]->getTrain()[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 d535d69876..d382ed0a55 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 3519a1be76..51463ef413 100644 --- a/modules/datasetstools/samples/fr_lfw.cpp +++ b/modules/datasetstools/samples/fr_lfw.cpp @@ -65,13 +65,14 @@ 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("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + FR_lfwObj *example = static_cast(dataset->getTrain()[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) diff --git a/modules/datasetstools/samples/gr_chalearn.cpp b/modules/datasetstools/samples/gr_chalearn.cpp index c9a8686066..e263cb2915 100644 --- a/modules/datasetstools/samples/gr_chalearn.cpp +++ b/modules/datasetstools/samples/gr_chalearn.cpp @@ -65,13 +65,14 @@ 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("dataset size: %u\n", (unsigned int)dataset->getTrain().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("depth video:\n%s\n", example->nameDepth.c_str()); diff --git a/modules/datasetstools/samples/gr_skig.cpp b/modules/datasetstools/samples/gr_skig.cpp index eb8e1b9760..9eb099049a 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 56b8ff0318..b99ee189ee 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 1101b86f68..06bc2f227c 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 bdd4d27f8e..69dc75ecf4 100644 --- a/modules/datasetstools/samples/ir_robot.cpp +++ b/modules/datasetstools/samples/ir_robot.cpp @@ -65,19 +65,20 @@ 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()); + IR_robotObj *example = static_cast(dataset->getTrain().back().get()); printf("last 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()); } - 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 dfa5f8a9e7..4c27954a52 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 255e77a38d..6ee152fa1e 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 b8d76c7678..17394a59d0 100644 --- a/modules/datasetstools/samples/msm_epfl.cpp +++ b/modules/datasetstools/samples/msm_epfl.cpp @@ -65,13 +65,14 @@ 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"); diff --git a/modules/datasetstools/samples/msm_middlebury.cpp b/modules/datasetstools/samples/msm_middlebury.cpp index 97eed4e704..20f030e062 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 94e779d7f1..99f13123b3 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_sun.cpp b/modules/datasetstools/samples/or_sun.cpp index 447233a298..0804d89364 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 d82e616209..c2112208eb 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 c93060aa24..af20372b70 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); @@ -90,7 +91,7 @@ int main(int argc, char *argv[]) { 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 e2c5a35069..d78f846202 100644 --- a/modules/datasetstools/samples/tr_chars.cpp +++ b/modules/datasetstools/samples/tr_chars.cpp @@ -66,15 +66,15 @@ int main(int argc, char *argv[]) return -1; } - vector dataset; + vector< Ptr > dataset; do { - TR_chars curr; + Ptr curr = TR_chars::create(); dataset.push_back(curr); int number = (int)dataset.size()-1; - dataset.back().load(path, number); - } while (dataset.back().train.size()>0); + dataset.back()->load(path, number); + } while (dataset.back()->getTrain().size()>0); dataset.pop_back(); // remove last empty split // *************** @@ -83,8 +83,8 @@ int main(int argc, char *argv[]) // And number of splits. printf("splits number: %u\n", (unsigned int)dataset.size()); - vector< Ptr > &currTrain = dataset.back().train; - vector< Ptr > &currTest = dataset.back().test; + vector< Ptr > &currTrain = dataset.back()->getTrain(); + vector< Ptr > &currTest = dataset.back()->getTest(); printf("train size: %u\n", (unsigned int)currTrain.size()); printf("test size: %u\n", (unsigned int)currTest.size()); diff --git a/modules/datasetstools/samples/tr_svt.cpp b/modules/datasetstools/samples/tr_svt.cpp index 563db00ffe..9dc05303e2 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 1df15eced9..1aa8c4d896 100644 --- a/modules/datasetstools/src/ar_hmdb.cpp +++ b/modules/datasetstools/src/ar_hmdb.cpp @@ -49,7 +49,22 @@ 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 std::string &path, int number = 0); + virtual ~AR_hmdbImp() {} + + 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_); +}; + +void AR_hmdbImp::loadAction(const string &fileName, vector &train_, vector &test_) { ifstream infile(fileName.c_str()); string video, label; @@ -66,17 +81,17 @@ 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_hmdb::load(const string &path, int number) +void AR_hmdbImp::load(const string &path, int number) { loadDataset(path, number); } -void AR_hmdb::loadDataset(const string &path, int number) +void AR_hmdbImp::loadDataset(const string &path, int number) { // valid number [0,1,2] if (number<0 || number>2) @@ -106,5 +121,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 e8533ccfff..c13e679769 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 std::string &path); + virtual ~AR_sportsImp() {} + + 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_); +}; + +void AR_sportsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) { ifstream infile(fileName.c_str()); string videoUrl, labels; @@ -69,12 +84,12 @@ 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, int number) { if (number!=0) { @@ -84,7 +99,7 @@ void AR_sports::load(const string &path, int number) loadDataset(path); } -void AR_sports::loadDataset(const string &path) +void AR_sportsImp::loadDataset(const string &path) { string trainPath(path + "original/train_partition.txt"); string testPath(path + "original/test_partition.txt"); @@ -96,5 +111,10 @@ void AR_sports::loadDataset(const string &path) loadDatasetPart(testPath, test); } +Ptr AR_sports::create() +{ + return Ptr(new AR_sportsImp); +} + } } diff --git a/modules/datasetstools/src/fr_lfw.cpp b/modules/datasetstools/src/fr_lfw.cpp index 0e736fd5d1..a394ab5069 100644 --- a/modules/datasetstools/src/fr_lfw.cpp +++ b/modules/datasetstools/src/fr_lfw.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -FR_lfw::FR_lfw(const string &path) +class CV_EXPORTS FR_lfwImp : public FR_lfw +{ +public: + FR_lfwImp() {} + //FR_lfwImp(const std::string &path); + virtual ~FR_lfwImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*FR_lfwImp::FR_lfwImp(const string &path) { loadDataset(path); -} +}*/ -void FR_lfw::load(const string &path, int number) +void FR_lfwImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void FR_lfw::load(const string &path, int number) loadDataset(path); } -void FR_lfw::loadDataset(const string &path) +void FR_lfwImp::loadDataset(const string &path) { vector fileNames; getDirList(path, fileNames); @@ -85,5 +98,10 @@ void FR_lfw::loadDataset(const string &path) } } +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 96003ab58a..483e9e3bfc 100644 --- a/modules/datasetstools/src/gr_chalearn.cpp +++ b/modules/datasetstools/src/gr_chalearn.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -GR_chalearn::GR_chalearn(const string &path) +class CV_EXPORTS GR_chalearnImp : public GR_chalearn +{ +public: + GR_chalearnImp() {} + //GR_chalearnImp(const std::string &path); + virtual ~GR_chalearnImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*GR_chalearnImp::GR_chalearnImp(const string &path) { loadDataset(path); -} +}*/ -void GR_chalearn::load(const string &path, int number) +void GR_chalearnImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void GR_chalearn::load(const string &path, int number) loadDataset(path); } -void GR_chalearn::loadDataset(const string &path) +void GR_chalearnImp::loadDataset(const string &path) { vector fileNames; getDirList(path, fileNames); @@ -133,5 +146,10 @@ void GR_chalearn::loadDataset(const string &path) } } +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 0f32b9fde9..193717366e 100644 --- a/modules/datasetstools/src/gr_skig.cpp +++ b/modules/datasetstools/src/gr_skig.cpp @@ -51,12 +51,25 @@ namespace datasetstools using namespace std; -GR_skig::GR_skig(const string &path) +class CV_EXPORTS GR_skigImp : public GR_skig +{ +public: + GR_skigImp() {} + //GR_skigImp(const std::string &path); + virtual ~GR_skigImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*GR_skigImp::GR_skigImp(const string &path) { loadDataset(path); -} +}*/ -void GR_skig::load(const string &path, int number) +void GR_skigImp::load(const string &path, int number) { if (number!=0) { @@ -66,7 +79,7 @@ void GR_skig::load(const string &path, int number) loadDataset(path); } -void GR_skig::loadDataset(const string &path) +void GR_skigImp::loadDataset(const string &path) { for (unsigned int i=1; i<=6; ++i) { @@ -103,5 +116,10 @@ void GR_skig::loadDataset(const string &path) } } +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 f0ee8fc0cb..dab81512fe 100644 --- a/modules/datasetstools/src/hpe_parse.cpp +++ b/modules/datasetstools/src/hpe_parse.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -HPE_parse::HPE_parse(const string &path) +class CV_EXPORTS HPE_parseImp : public HPE_parse +{ +public: + HPE_parseImp() {} + //HPE_parseImp(const std::string &path); + virtual ~HPE_parseImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*HPE_parseImp::HPE_parseImp(const string &path) { loadDataset(path); -} +}*/ -void HPE_parse::load(const string &path, int number) +void HPE_parseImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void HPE_parse::load(const string &path, int number) loadDataset(path); } -void HPE_parse::loadDataset(const string &path) +void HPE_parseImp::loadDataset(const string &path) { unsigned int i=0; vector fileNames; @@ -94,5 +107,10 @@ void HPE_parse::loadDataset(const string &path) } } +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 5ad3dac2c7..7923284e2b 100644 --- a/modules/datasetstools/src/ir_affine.cpp +++ b/modules/datasetstools/src/ir_affine.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -IR_affine::IR_affine(const string &path) +class CV_EXPORTS IR_affineImp : public IR_affine +{ +public: + IR_affineImp() {} + //IR_affineImp(const std::string &path); + virtual ~IR_affineImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*IR_affineImp::IR_affineImp(const string &path) { loadDataset(path); -} +}*/ -void IR_affine::load(const string &path, int number) +void IR_affineImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void IR_affine::load(const string &path, int number) loadDataset(path); } -void IR_affine::loadDataset(const string &path) +void IR_affineImp::loadDataset(const string &path) { for (unsigned int i=1; i<=6; ++i) { @@ -91,5 +104,10 @@ void IR_affine::loadDataset(const string &path) } } +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 65c17b73c2..a2a523b980 100644 --- a/modules/datasetstools/src/ir_robot.cpp +++ b/modules/datasetstools/src/ir_robot.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -IR_robot::IR_robot(const string &path) +class CV_EXPORTS IR_robotImp : public IR_robot +{ +public: + IR_robotImp() {} + //IR_robotImp(const std::string &path); + virtual ~IR_robotImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*IR_robotImp::IR_robotImp(const string &path) { loadDataset(path); -} +}*/ -void IR_robot::load(const string &path, int number) +void IR_robotImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void IR_robot::load(const string &path, int number) loadDataset(path); } -void IR_robot::loadDataset(const string &path) +void IR_robotImp::loadDataset(const string &path) { vector fileNames; getDirList(path, fileNames); @@ -85,5 +98,10 @@ void IR_robot::loadDataset(const string &path) } } +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 270fcc8d34..13a723e458 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 std::string &path); + virtual ~IS_bsdsImp() {} + + 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_); +}; + +void IS_bsdsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) { ifstream infile(fileName.c_str()); string imageName; @@ -61,12 +76,12 @@ 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, int number) { if (number!=0) { @@ -76,7 +91,7 @@ void IS_bsds::load(const string &path, int number) loadDataset(path); } -void IS_bsds::loadDataset(const string &path) +void IS_bsdsImp::loadDataset(const string &path) { string trainName(path + "iids_train.txt"); string testName(path + "iids_test.txt"); @@ -88,5 +103,10 @@ void IS_bsds::loadDataset(const string &path) loadDatasetPart(testName, test); } +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 a1d6b332fd..ca2d7c5475 100644 --- a/modules/datasetstools/src/is_weizmann.cpp +++ b/modules/datasetstools/src/is_weizmann.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -IS_weizmann::IS_weizmann(const string &path) +class CV_EXPORTS IS_weizmannImp : public IS_weizmann +{ +public: + IS_weizmannImp() {} + //IS_weizmannImp(const std::string &path); + virtual ~IS_weizmannImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*IS_weizmannImp::IS_weizmannImp(const string &path) { loadDataset(path); -} +}*/ -void IS_weizmann::load(const string &path, int number) +void IS_weizmannImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void IS_weizmann::load(const string &path, int number) loadDataset(path); } -void IS_weizmann::loadDataset(const string &path) +void IS_weizmannImp::loadDataset(const string &path) { vector fileNames; getDirList(path, fileNames); @@ -85,5 +98,10 @@ void IS_weizmann::loadDataset(const string &path) } } +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 195d30d027..1e64f3df14 100644 --- a/modules/datasetstools/src/msm_epfl.cpp +++ b/modules/datasetstools/src/msm_epfl.cpp @@ -49,7 +49,22 @@ namespace datasetstools using namespace std; -void MSM_epfl::readFileDouble(const string &fileName, vector &out) +class CV_EXPORTS MSM_epflImp : public MSM_epfl +{ +public: + MSM_epflImp() {} + //MSM_epflImp(const std::string &path); + virtual ~MSM_epflImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); + + void readFileDouble(const std::string &fileName, std::vector &out); +}; + +void MSM_epflImp::readFileDouble(const string &fileName, vector &out) { ifstream infile(fileName.c_str()); double val; @@ -59,12 +74,12 @@ void MSM_epfl::readFileDouble(const string &fileName, vector &out) } } -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, int number) { if (number!=0) { @@ -74,7 +89,7 @@ void MSM_epfl::load(const string &path, int number) loadDataset(path); } -void MSM_epfl::loadDataset(const string &path) +void MSM_epflImp::loadDataset(const string &path) { string pathBounding(path + "bounding/"); string pathCamera(path + "camera/"); @@ -96,5 +111,10 @@ void MSM_epfl::loadDataset(const string &path) } } +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 a94f84fcb0..88a817233c 100644 --- a/modules/datasetstools/src/msm_middlebury.cpp +++ b/modules/datasetstools/src/msm_middlebury.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -MSM_middlebury::MSM_middlebury(const string &path) +class CV_EXPORTS MSM_middleburyImp : public MSM_middlebury +{ +public: + MSM_middleburyImp() {} + //MSM_middleburyImp(const std::string &path); + virtual ~MSM_middleburyImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*MSM_middleburyImp::MSM_middleburyImp(const string &path) { loadDataset(path); -} +}*/ -void MSM_middlebury::load(const string &path, int number) +void MSM_middleburyImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void MSM_middlebury::load(const string &path, int number) loadDataset(path); } -void MSM_middlebury::loadDataset(const string &path) +void MSM_middleburyImp::loadDataset(const string &path) { string name(path.substr(0, path.length()-1)); size_t start = name.rfind('/'); @@ -85,14 +98,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) @@ -104,5 +117,10 @@ void MSM_middlebury::loadDataset(const string &path) } } +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 740790c7f3..6f327c959b 100644 --- a/modules/datasetstools/src/or_imagenet.cpp +++ b/modules/datasetstools/src/or_imagenet.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -OR_imagenet::OR_imagenet(const string &path) +class CV_EXPORTS OR_imagenetImp : public OR_imagenet +{ +public: + OR_imagenetImp() {} + //OR_imagenetImp(const std::string &path); + virtual ~OR_imagenetImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*OR_imagenetImp::OR_imagenetImp(const string &path) { loadDataset(path); -} +}*/ -void OR_imagenet::load(const string &path, int number) +void OR_imagenetImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void OR_imagenet::load(const string &path, int number) loadDataset(path); } -void OR_imagenet::loadDataset(const string &path) +void OR_imagenetImp::loadDataset(const string &path) { ifstream infile((path + "fall11_urls.txt").c_str()); string line; @@ -83,11 +96,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); } } +Ptr OR_imagenet::create() +{ + return Ptr(new OR_imagenetImp); +} + } } diff --git a/modules/datasetstools/src/or_sun.cpp b/modules/datasetstools/src/or_sun.cpp index 7732c4cc9d..c332617dd5 100644 --- a/modules/datasetstools/src/or_sun.cpp +++ b/modules/datasetstools/src/or_sun.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -OR_sun::OR_sun(const string &path) +class CV_EXPORTS OR_sunImp : public OR_sun +{ +public: + OR_sunImp() {} + //OR_sunImp(const std::string &path); + virtual ~OR_sunImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*OR_sunImp::OR_sunImp(const string &path) { loadDataset(path); -} +}*/ -void OR_sun::load(const string &path, int number) +void OR_sunImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void OR_sun::load(const string &path, int number) loadDataset(path); } -void OR_sun::loadDataset(const string &path) +void OR_sunImp::loadDataset(const string &path) { string classNameFile(path + "ClassName.txt"); ifstream infile(classNameFile.c_str()); @@ -86,5 +99,10 @@ void OR_sun::loadDataset(const string &path) } } +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 d659720fee..6414d25b74 100644 --- a/modules/datasetstools/src/slam_kitti.cpp +++ b/modules/datasetstools/src/slam_kitti.cpp @@ -49,12 +49,25 @@ namespace datasetstools using namespace std; -SLAM_kitti::SLAM_kitti(const string &path) +class CV_EXPORTS SLAM_kittiImp : public SLAM_kitti +{ +public: + SLAM_kittiImp() {} + //SLAM_kittiImp(const std::string &path); + virtual ~SLAM_kittiImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*SLAM_kittiImp::SLAM_kittiImp(const string &path) { loadDataset(path); -} +}*/ -void SLAM_kitti::load(const string &path, int number) +void SLAM_kittiImp::load(const string &path, int number) { if (number!=0) { @@ -64,7 +77,7 @@ void SLAM_kitti::load(const string &path, int number) loadDataset(path); } -void SLAM_kitti::loadDataset(const string &path) +void SLAM_kittiImp::loadDataset(const string &path) { string pathSequence(path + "sequences/"); vector fileNames; @@ -146,5 +159,10 @@ void SLAM_kitti::loadDataset(const string &path) } } +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 fc60336384..5b689aab36 100644 --- a/modules/datasetstools/src/slam_tumindoor.cpp +++ b/modules/datasetstools/src/slam_tumindoor.cpp @@ -51,12 +51,25 @@ 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 std::string &path); + virtual ~SLAM_tumindoorImp() {} + + virtual void load(const std::string &path, int number = 0); + +private: + void loadDataset(const std::string &path); +}; + +/*SLAM_tumindoorImp::SLAM_tumindoorImp(const string &path) { loadDataset(path); -} +}*/ -void SLAM_tumindoor::load(const string &path, int number) +void SLAM_tumindoorImp::load(const string &path, int number) { if (number!=0) { @@ -66,7 +79,7 @@ void SLAM_tumindoor::load(const string &path, int number) loadDataset(path); } -void SLAM_tumindoor::loadDataset(const string &path) +void SLAM_tumindoorImp::loadDataset(const string &path) { string infoPath(path + "info/2011-12-17_15.02.56-info.csv"); // TODO ifstream infile(infoPath.c_str()); @@ -95,7 +108,7 @@ 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()); } } @@ -103,5 +116,10 @@ void SLAM_tumindoor::loadDataset(const string &path) } } +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 a229cc14d3..2066e1b2c2 100644 --- a/modules/datasetstools/src/tr_chars.cpp +++ b/modules/datasetstools/src/tr_chars.cpp @@ -49,7 +49,22 @@ 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 std::string &path, int number = 0); + virtual ~TR_charsImp() {} + + 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); +}; + +void TR_charsImp::parseLine(const string &line, vector &currSet, int number) { vector elems; split(line, elems, ' '); @@ -65,17 +80,17 @@ void TR_chars::parseLine(const string &line, vector &currSet, int number) } } -TR_chars::TR_chars(const string &path, int number) +/*TR_charsImp::TR_charsImp(const string &path, int number) { loadDataset(path, number); -} +}*/ -void TR_chars::load(const string &path, int number) +void TR_charsImp::load(const string &path, int number) { loadDataset(path, number); } -void TR_chars::loadDataset(const string &path, int number) +void TR_charsImp::loadDataset(const string &path, int number) { vector allLabels, trainSet, testSet; vector allNames; @@ -184,5 +199,10 @@ void TR_chars::loadDataset(const string &path, int number) } } +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 c803c1c668..6a3b9db8a6 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 std::string &path); + virtual ~TR_svtImp() {} + + 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); +}; + +void TR_svtImp::xmlParse(const string &set, vector< Ptr > &out) { XMLDocument doc; doc.LoadFile(set.c_str()); @@ -97,12 +112,12 @@ 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, int number) { if (number!=0) { @@ -112,7 +127,7 @@ void TR_svt::load(const string &path, int number) loadDataset(path); } -void TR_svt::loadDataset(const string &path) +void TR_svtImp::loadDataset(const string &path) { string trainXml(path + "train.xml"); string testXml(path + "test.xml"); @@ -124,5 +139,10 @@ void TR_svt::loadDataset(const string &path) xmlParse(testXml, test); } +Ptr TR_svt::create() +{ + return Ptr(new TR_svtImp); +} + } } From 444480df2d1b0498449e5c4af46e43480911b179 Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Thu, 4 Sep 2014 17:00:56 +0400 Subject: [PATCH 2/8] several enhancements --- modules/datasetstools/doc/datasetstools.rst | 8 +- .../include/opencv2/datasetstools/dataset.hpp | 2 + .../opencv2/datasetstools/ir_robot.hpp | 7 +- .../opencv2/datasetstools/msm_epfl.hpp | 13 +- modules/datasetstools/samples/gr_chalearn.cpp | 5 +- modules/datasetstools/samples/ir_robot.cpp | 12 +- modules/datasetstools/samples/msm_epfl.cpp | 54 ++++++-- .../datasetstools/samples/slam_tumindoor.cpp | 2 +- modules/datasetstools/samples/tr_chars.cpp | 17 ++- modules/datasetstools/src/gr_chalearn.cpp | 39 ++++-- modules/datasetstools/src/gr_skig.cpp | 34 ++++-- modules/datasetstools/src/ir_robot.cpp | 13 +- modules/datasetstools/src/msm_epfl.cpp | 67 +++++++--- modules/datasetstools/src/slam_tumindoor.cpp | 30 ++++- modules/datasetstools/src/tr_chars.cpp | 115 +++++++++--------- 15 files changed, 289 insertions(+), 129 deletions(-) diff --git a/modules/datasetstools/doc/datasetstools.rst b/modules/datasetstools/doc/datasetstools.rst index 76d27130ba..acdc3a5602 100644 --- a/modules/datasetstools/doc/datasetstools.rst +++ b/modules/datasetstools/doc/datasetstools.rst @@ -75,9 +75,11 @@ _`"ChaLearn Looking at People"`: http://gesture.chalearn.org/ 1. Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": Train1.zip-Train5.zip, Validation1.zip-Validation3.zip (Register on site: www.codalab.org and accept the terms and conditions of competition: https://www.codalab.org/competitions/991#learn_the_details There are three mirrors for downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" works). - 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 ======= @@ -245,7 +247,7 @@ 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/dataset.hpp b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp index 544719bbfb..afac7bc68e 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp @@ -66,10 +66,12 @@ class CV_EXPORTS Dataset std::vector< Ptr >& getTrain() { return train; } std::vector< Ptr >& getTest() { return test; } + std::vector< Ptr >& getValidation() { return validation; } protected: std::vector< Ptr > train; std::vector< Ptr > test; + std::vector< Ptr > validation; }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp index efb76ef4ff..9d69522042 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp @@ -59,10 +59,15 @@ 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 diff --git a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp index 22633667e6..b71c8d8faa 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp @@ -54,10 +54,21 @@ 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 diff --git a/modules/datasetstools/samples/gr_chalearn.cpp b/modules/datasetstools/samples/gr_chalearn.cpp index e263cb2915..fa972667e9 100644 --- a/modules/datasetstools/samples/gr_chalearn.cpp +++ b/modules/datasetstools/samples/gr_chalearn.cpp @@ -71,10 +71,11 @@ int main(int argc, char *argv[]) // *************** // dataset contains information for each sample. // For example, let output dataset size and first element. - printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("train size: %u\n", (unsigned int)dataset->getTrain().size()); + printf("validation size: %u\n", (unsigned int)dataset->getValidation().size()); GR_chalearnObj *example = static_cast(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/ir_robot.cpp b/modules/datasetstools/samples/ir_robot.cpp index 69dc75ecf4..b06eb327bc 100644 --- a/modules/datasetstools/samples/ir_robot.cpp +++ b/modules/datasetstools/samples/ir_robot.cpp @@ -72,11 +72,17 @@ int main(int argc, char *argv[]) // dataset contains object with name and its images. // For example, let output last element and dataset size. IR_robotObj *example = static_cast(dataset->getTrain().back().get()); - printf("last dataset object:\n%s\n", example->name.c_str()); + printf("last dataset object:\n"); + printf("name: %s\n", example->name.c_str()); + printf("number postitions: %u\n", (unsigned int)example->pos.size()); string currPath(path + example->name + "/"); - 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->getTrain().size()); diff --git a/modules/datasetstools/samples/msm_epfl.cpp b/modules/datasetstools/samples/msm_epfl.cpp index 17394a59d0..f80f340b51 100644 --- a/modules/datasetstools/samples/msm_epfl.cpp +++ b/modules/datasetstools/samples/msm_epfl.cpp @@ -75,26 +75,60 @@ int main(int argc, char *argv[]) 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/slam_tumindoor.cpp b/modules/datasetstools/samples/slam_tumindoor.cpp index af20372b70..2ba504b661 100644 --- a/modules/datasetstools/samples/slam_tumindoor.cpp +++ b/modules/datasetstools/samples/slam_tumindoor.cpp @@ -86,7 +86,7 @@ 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) diff --git a/modules/datasetstools/samples/tr_chars.cpp b/modules/datasetstools/samples/tr_chars.cpp index d78f846202..499d831a14 100644 --- a/modules/datasetstools/samples/tr_chars.cpp +++ b/modules/datasetstools/samples/tr_chars.cpp @@ -85,15 +85,20 @@ int main(int argc, char *argv[]) vector< Ptr > &currTrain = dataset.back()->getTrain(); vector< Ptr > &currTest = dataset.back()->getTest(); + vector< Ptr > &currValidation = dataset.back()->getValidation(); 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/src/gr_chalearn.cpp b/modules/datasetstools/src/gr_chalearn.cpp index 483e9e3bfc..a27d16f9bc 100644 --- a/modules/datasetstools/src/gr_chalearn.cpp +++ b/modules/datasetstools/src/gr_chalearn.cpp @@ -60,6 +60,8 @@ class CV_EXPORTS GR_chalearnImp : public GR_chalearn private: void loadDataset(const std::string &path); + + void loadDatasetPart(const std::string &path, std::vector< Ptr > &dataset_, bool loadLabels); }; /*GR_chalearnImp::GR_chalearnImp(const string &path) @@ -77,7 +79,7 @@ void GR_chalearnImp::load(const string &path, int number) loadDataset(path); } -void GR_chalearnImp::loadDataset(const string &path) +void GR_chalearnImp::loadDatasetPart(const string &path, vector< Ptr > &dataset_, bool loadLabels) { vector fileNames; getDirList(path, fileNames); @@ -101,19 +103,22 @@ void GR_chalearnImp::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 @@ -142,10 +147,20 @@ void GR_chalearnImp::loadDataset(const string &path) curr->skeletons.push_back(currSkeleton); } - train.push_back(curr); + dataset_.push_back(curr); } } +void GR_chalearnImp::loadDataset(const string &path) +{ + string pathTrain(path + "Train/"); + loadDatasetPart(pathTrain, train, true); + + // freely available validation set doesn't have labels + string pathValidation(path + "Validation/"); + loadDatasetPart(pathValidation, validation, false); +} + Ptr GR_chalearn::create() { return Ptr(new GR_chalearnImp); diff --git a/modules/datasetstools/src/gr_skig.cpp b/modules/datasetstools/src/gr_skig.cpp index 193717366e..aeecba7b62 100644 --- a/modules/datasetstools/src/gr_skig.cpp +++ b/modules/datasetstools/src/gr_skig.cpp @@ -100,18 +100,28 @@ void GR_skigImp::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.push_back(curr); + } else + { + printf("incorrect file name: %s", file.c_str()); + } } } } diff --git a/modules/datasetstools/src/ir_robot.cpp b/modules/datasetstools/src/ir_robot.cpp index a2a523b980..71b0c33ff0 100644 --- a/modules/datasetstools/src/ir_robot.cpp +++ b/modules/datasetstools/src/ir_robot.cpp @@ -89,9 +89,20 @@ void IR_robotImp::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); diff --git a/modules/datasetstools/src/msm_epfl.cpp b/modules/datasetstools/src/msm_epfl.cpp index 1e64f3df14..798b5f97ec 100644 --- a/modules/datasetstools/src/msm_epfl.cpp +++ b/modules/datasetstools/src/msm_epfl.cpp @@ -60,20 +60,8 @@ class CV_EXPORTS MSM_epflImp : public MSM_epfl private: void loadDataset(const std::string &path); - - void readFileDouble(const std::string &fileName, std::vector &out); }; -void MSM_epflImp::readFileDouble(const string &fileName, vector &out) -{ - ifstream infile(fileName.c_str()); - double val; - while (infile >> val) - { - out.push_back(val); - } -} - /*MSM_epflImp::MSM_epflImp(const string &path) { loadDataset(path); @@ -103,9 +91,58 @@ void MSM_epflImp::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); + } + } + + // load camera parameters + string fileCamera(pathCamera + curr->imageName + ".camera"); + ifstream infileCamera(fileCamera.c_str()); + for (int i=0; i<3; ++i) + { + for (int j=0; j<3; ++j) + { + infileCamera >> curr->camera.mat1(i, j); + } + } + + for (int i=0; i<3; ++i) + { + infileCamera >> curr->camera.mat2[i]; + } + + for (int i=0; i<3; ++i) + { + for (int j=0; j<3; ++j) + { + infileCamera >> curr->camera.mat3(i, j); + } + } + + for (int i=0; i<3; ++i) + { + infileCamera >> curr->camera.mat4[i]; + } + + infileCamera >> curr->camera.imageWidth >> curr->camera.imageHeight; + + // load P + string fileP(pathP + curr->imageName + ".P"); + ifstream infileP(fileP.c_str()); + for (int k=0; k<3; ++k) + { + for (int j=0; j<4; ++j) + { + infileP >> curr->p(k, j); + } + } train.push_back(curr); } diff --git a/modules/datasetstools/src/slam_tumindoor.cpp b/modules/datasetstools/src/slam_tumindoor.cpp index 5b689aab36..85dbc56357 100644 --- a/modules/datasetstools/src/slam_tumindoor.cpp +++ b/modules/datasetstools/src/slam_tumindoor.cpp @@ -81,8 +81,34 @@ void SLAM_tumindoorImp::load(const string &path, int number) void SLAM_tumindoorImp::loadDataset(const string &path) { - string infoPath(path + "info/2011-12-17_15.02.56-info.csv"); // TODO - ifstream infile(infoPath.c_str()); + 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; + } + + ifstream infile((infoPath + csvName).c_str()); string line; while (getline(infile, line)) { diff --git a/modules/datasetstools/src/tr_chars.cpp b/modules/datasetstools/src/tr_chars.cpp index 2066e1b2c2..b157e9207a 100644 --- a/modules/datasetstools/src/tr_chars.cpp +++ b/modules/datasetstools/src/tr_chars.cpp @@ -53,15 +53,19 @@ class CV_EXPORTS TR_charsImp : public TR_chars { public: TR_charsImp() {} - //TR_charsImp(const std::string &path, int number = 0); + //TR_charsImp(const string &path, int number = 0); virtual ~TR_charsImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path, int number = 0); private: - void loadDataset(const std::string &path, int number = 0); + void loadDataset(const string &path, int number = 0); - void parseLine(const std::string &line, std::vector &currSet, int number); + 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) @@ -80,6 +84,38 @@ void TR_charsImp::parseLine(const string &line, vector &currSet, int number } } +inline void TR_charsImp::convert(vector &from, std::vector< Ptr > &to, vector &allLabels, vector &allNames) +{ + 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); + } +} + /*TR_charsImp::TR_charsImp(const string &path, int number) { loadDataset(path, number); @@ -92,21 +128,22 @@ void TR_charsImp::load(const string &path, int number) void TR_charsImp::loadDataset(const string &path, int number) { - vector allLabels, trainSet, testSet; + 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 = ["); @@ -124,7 +161,7 @@ void TR_charsImp::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(); @@ -137,66 +174,24 @@ void TR_charsImp::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; - } - - Ptr curr(new TR_charsObj); - curr->imgName = allNames[*it]; - curr->label = allLabels[*it]; - test.push_back(curr); - } + convert(trainSet, train, allLabels, allNames); + convert(testSet, test, allLabels, allNames); + convert(validationSet, validation, allLabels, allNames); } Ptr TR_chars::create() From ad14f83b040129e7f10a1f1b53f868c2d8e1b1af Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Fri, 5 Sep 2014 14:28:29 +0400 Subject: [PATCH 3/8] last planned large refactoring --- .../include/opencv2/datasetstools/ar_hmdb.hpp | 2 +- .../opencv2/datasetstools/ar_sports.hpp | 2 +- .../include/opencv2/datasetstools/dataset.hpp | 16 ++++---- .../include/opencv2/datasetstools/fr_lfw.hpp | 2 +- .../opencv2/datasetstools/gr_chalearn.hpp | 2 +- .../include/opencv2/datasetstools/gr_skig.hpp | 2 +- .../opencv2/datasetstools/hpe_parse.hpp | 2 +- .../opencv2/datasetstools/ir_affine.hpp | 2 +- .../opencv2/datasetstools/ir_robot.hpp | 2 +- .../include/opencv2/datasetstools/is_bsds.hpp | 2 +- .../opencv2/datasetstools/is_weizmann.hpp | 2 +- .../opencv2/datasetstools/msm_epfl.hpp | 2 +- .../opencv2/datasetstools/msm_middlebury.hpp | 2 +- .../opencv2/datasetstools/or_imagenet.hpp | 2 +- .../include/opencv2/datasetstools/or_sun.hpp | 2 +- .../opencv2/datasetstools/slam_kitti.hpp | 2 +- .../opencv2/datasetstools/slam_tumindoor.hpp | 2 +- .../opencv2/datasetstools/tr_chars.hpp | 2 +- .../include/opencv2/datasetstools/tr_svt.hpp | 2 +- modules/datasetstools/samples/ar_hmdb.cpp | 10 ++--- modules/datasetstools/samples/tr_chars.cpp | 21 ++++------ modules/datasetstools/src/ar_hmdb.cpp | 32 +++++++++++----- modules/datasetstools/src/ar_sports.cpp | 23 ++++++----- modules/datasetstools/src/fr_lfw.cpp | 19 +++++----- modules/datasetstools/src/gr_chalearn.cpp | 23 ++++++----- modules/datasetstools/src/gr_skig.cpp | 19 +++++----- modules/datasetstools/src/hpe_parse.cpp | 21 +++++----- modules/datasetstools/src/ir_affine.cpp | 19 +++++----- modules/datasetstools/src/ir_robot.cpp | 21 +++++----- modules/datasetstools/src/is_bsds.cpp | 23 ++++++----- modules/datasetstools/src/is_weizmann.cpp | 19 +++++----- modules/datasetstools/src/msm_epfl.cpp | 19 +++++----- modules/datasetstools/src/msm_middlebury.cpp | 19 +++++----- modules/datasetstools/src/or_imagenet.cpp | 19 +++++----- modules/datasetstools/src/or_sun.cpp | 19 +++++----- modules/datasetstools/src/slam_kitti.cpp | 19 +++++----- modules/datasetstools/src/slam_tumindoor.cpp | 19 +++++----- modules/datasetstools/src/tr_chars.cpp | 38 ++++++++++++++----- modules/datasetstools/src/tr_svt.cpp | 23 ++++++----- 39 files changed, 243 insertions(+), 234 deletions(-) diff --git a/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp b/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp index a118586216..85e159702f 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ar_hmdb.hpp @@ -63,7 +63,7 @@ struct AR_hmdbObj : public Object class CV_EXPORTS AR_hmdb : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp b/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp index 0b44d8ee32..408e2fca5b 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ar_sports.hpp @@ -63,7 +63,7 @@ struct AR_sportsObj : public Object class CV_EXPORTS AR_sports : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp index afac7bc68e..a12be84804 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp @@ -62,16 +62,18 @@ class CV_EXPORTS Dataset 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 >& getTrain() { return train; } - std::vector< Ptr >& getTest() { return test; } - std::vector< Ptr >& getValidation() { return validation; } + std::vector< Ptr >& getTrain(int splitNum = 0) { return train[splitNum]; } + std::vector< Ptr >& getTest(int splitNum = 0) { return test[splitNum]; } + std::vector< Ptr >& getValidation(int splitNum = 0) { return validation[splitNum]; } + + int getNumSplits() const { return train.size(); } protected: - std::vector< Ptr > train; - std::vector< Ptr > test; - std::vector< Ptr > validation; + std::vector< std::vector< Ptr > > train; + std::vector< std::vector< Ptr > > test; + std::vector< std::vector< Ptr > > validation; }; } diff --git a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp index a1866269b3..1fcdd3a42f 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp @@ -63,7 +63,7 @@ struct FR_lfwObj : public Object class CV_EXPORTS FR_lfw : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp b/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp index 66e071a03a..efadb605d9 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/gr_chalearn.hpp @@ -80,7 +80,7 @@ struct GR_chalearnObj : public Object class CV_EXPORTS GR_chalearn : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp b/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp index abaad74821..79cfcdeb4d 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/gr_skig.hpp @@ -102,7 +102,7 @@ struct GR_skigObj : public Object class CV_EXPORTS GR_skig : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp b/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp index 197e14c797..7d1d1b15ac 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/hpe_parse.hpp @@ -62,7 +62,7 @@ struct HPE_parseObj : public Object class CV_EXPORTS HPE_parse : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp b/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp index 763514c76b..b3cc8782a3 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_affine.hpp @@ -64,7 +64,7 @@ struct IR_affineObj : public Object class CV_EXPORTS IR_affine : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp index 9d69522042..fe319ba14f 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/ir_robot.hpp @@ -73,7 +73,7 @@ struct IR_robotObj : public Object class CV_EXPORTS IR_robot : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp b/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp index 40232b075a..880b2fcb77 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/is_bsds.hpp @@ -62,7 +62,7 @@ struct IS_bsdsObj : public Object class CV_EXPORTS IS_bsds : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp b/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp index c8cb1f058a..66184489fe 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/is_weizmann.hpp @@ -65,7 +65,7 @@ struct IS_weizmannObj : public Object class CV_EXPORTS IS_weizmann : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp index b71c8d8faa..1aecf6f66a 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_epfl.hpp @@ -74,7 +74,7 @@ struct MSM_epflObj : public Object class CV_EXPORTS MSM_epfl : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp b/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp index c52ba41b95..cbfbb38be1 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/msm_middlebury.hpp @@ -65,7 +65,7 @@ struct MSM_middleburyObj : public Object class CV_EXPORTS MSM_middlebury : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp index 05fd1414eb..ac401f930b 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/or_imagenet.hpp @@ -64,7 +64,7 @@ struct OR_imagenetObj : public Object class CV_EXPORTS OR_imagenet : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp b/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp index f14aaea44d..f231d6d208 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/or_sun.hpp @@ -63,7 +63,7 @@ struct OR_sunObj : public Object class CV_EXPORTS OR_sun : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp b/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp index 68fd3416ab..f133eb1341 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/slam_kitti.hpp @@ -71,7 +71,7 @@ struct SLAM_kittiObj : public Object class CV_EXPORTS SLAM_kitti : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp b/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp index a35e84ed6a..4945dca33d 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/slam_tumindoor.hpp @@ -71,7 +71,7 @@ struct SLAM_tumindoorObj : public Object class CV_EXPORTS SLAM_tumindoor : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp b/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp index 3c61efe054..c8207b45fc 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/tr_chars.hpp @@ -63,7 +63,7 @@ struct TR_charsObj : public Object class CV_EXPORTS TR_chars : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp b/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp index 57c50f791b..eb014af95d 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/tr_svt.hpp @@ -70,7 +70,7 @@ struct TR_svtObj : public Object class CV_EXPORTS TR_svt : public Dataset { public: - virtual void load(const std::string &path, int number = 0) = 0; + virtual void load(const std::string &path) = 0; static Ptr create(); }; diff --git a/modules/datasetstools/samples/ar_hmdb.cpp b/modules/datasetstools/samples/ar_hmdb.cpp index 82c67da2a9..b45297cc3c 100644 --- a/modules/datasetstools/samples/ar_hmdb.cpp +++ b/modules/datasetstools/samples/ar_hmdb.cpp @@ -65,18 +65,14 @@ int main(int argc, char *argv[]) return -1; } - Ptr dataset[3]; - for (int i=0; i<3; ++i) - { - dataset[i] = AR_hmdb::create(); - 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]->getTrain()[0].get()); + AR_hmdbObj *example = static_cast(dataset->getTrain()[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/tr_chars.cpp b/modules/datasetstools/samples/tr_chars.cpp index 499d831a14..0dd28d6f7f 100644 --- a/modules/datasetstools/samples/tr_chars.cpp +++ b/modules/datasetstools/samples/tr_chars.cpp @@ -66,26 +66,19 @@ int main(int argc, char *argv[]) return -1; } - vector< Ptr > dataset; - do - { - Ptr curr = TR_chars::create(); - dataset.push_back(curr); - - int number = (int)dataset.size()-1; - dataset.back()->load(path, number); - } while (dataset.back()->getTrain().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()->getTrain(); - vector< Ptr > &currTest = dataset.back()->getTest(); - vector< Ptr > &currValidation = dataset.back()->getValidation(); + 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()); diff --git a/modules/datasetstools/src/ar_hmdb.cpp b/modules/datasetstools/src/ar_hmdb.cpp index 1aa8c4d896..d30d485079 100644 --- a/modules/datasetstools/src/ar_hmdb.cpp +++ b/modules/datasetstools/src/ar_hmdb.cpp @@ -53,15 +53,17 @@ class CV_EXPORTS AR_hmdbImp : public AR_hmdb { public: AR_hmdbImp() {} - //AR_hmdbImp(const std::string &path, int number = 0); + //AR_hmdbImp(const string &path, int number = 0); virtual ~AR_hmdbImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path, int number = 0); + void loadDatasetSplit(const string &path, int number = 0); - void loadAction(const std::string &fileName, std::vector &train_, std::vector &test_); + 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_) @@ -86,12 +88,20 @@ void AR_hmdbImp::loadAction(const string &fileName, vector &train_, vect loadDataset(path, number); }*/ -void AR_hmdbImp::load(const string &path, int number) +void AR_hmdbImp::load(const string &path) { - loadDataset(path, number); + loadDataset(path); +} + +void AR_hmdbImp::loadDataset(const string &path) +{ + for (int i=0; i<3; ++i) + { + loadDatasetSplit(path, i); + } } -void AR_hmdbImp::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) @@ -99,6 +109,10 @@ void AR_hmdbImp::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/"); @@ -111,8 +125,8 @@ void AR_hmdbImp::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); diff --git a/modules/datasetstools/src/ar_sports.cpp b/modules/datasetstools/src/ar_sports.cpp index c13e679769..0f4b4cf58d 100644 --- a/modules/datasetstools/src/ar_sports.cpp +++ b/modules/datasetstools/src/ar_sports.cpp @@ -53,15 +53,15 @@ class CV_EXPORTS AR_sportsImp : public AR_sports { public: AR_sportsImp() {} - //AR_sportsImp(const std::string &path); + //AR_sportsImp(const string &path); virtual ~AR_sportsImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); - void loadDatasetPart(const std::string &fileName, std::vector< Ptr > &dataset_); + void loadDatasetPart(const string &fileName, vector< Ptr > &dataset_); }; void AR_sportsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) @@ -89,26 +89,25 @@ void AR_sportsImp::loadDatasetPart(const string &fileName, vector< Ptr > loadDataset(path); }*/ -void AR_sportsImp::load(const string &path, int number) +void AR_sportsImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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() diff --git a/modules/datasetstools/src/fr_lfw.cpp b/modules/datasetstools/src/fr_lfw.cpp index a394ab5069..0c9f506fab 100644 --- a/modules/datasetstools/src/fr_lfw.cpp +++ b/modules/datasetstools/src/fr_lfw.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS FR_lfwImp : public FR_lfw { public: FR_lfwImp() {} - //FR_lfwImp(const std::string &path); + //FR_lfwImp(const string &path); virtual ~FR_lfwImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*FR_lfwImp::FR_lfwImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS FR_lfwImp : public FR_lfw loadDataset(path); }*/ -void FR_lfwImp::load(const string &path, int number) +void FR_lfwImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(path); } void FR_lfwImp::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) @@ -94,7 +93,7 @@ void FR_lfwImp::loadDataset(const string &path) curr->images.push_back(*itFace); } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/gr_chalearn.cpp b/modules/datasetstools/src/gr_chalearn.cpp index a27d16f9bc..b9380193b6 100644 --- a/modules/datasetstools/src/gr_chalearn.cpp +++ b/modules/datasetstools/src/gr_chalearn.cpp @@ -53,15 +53,15 @@ class CV_EXPORTS GR_chalearnImp : public GR_chalearn { public: GR_chalearnImp() {} - //GR_chalearnImp(const std::string &path); + //GR_chalearnImp(const string &path); virtual ~GR_chalearnImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); - void loadDatasetPart(const std::string &path, std::vector< Ptr > &dataset_, bool loadLabels); + void loadDatasetPart(const string &path, vector< Ptr > &dataset_, bool loadLabels); }; /*GR_chalearnImp::GR_chalearnImp(const string &path) @@ -69,13 +69,8 @@ class CV_EXPORTS GR_chalearnImp : public GR_chalearn loadDataset(path); }*/ -void GR_chalearnImp::load(const string &path, int number) +void GR_chalearnImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(path); } @@ -153,12 +148,16 @@ void GR_chalearnImp::loadDatasetPart(const string &path, vector< Ptr > & 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, true); + loadDatasetPart(pathTrain, train.back(), true); // freely available validation set doesn't have labels string pathValidation(path + "Validation/"); - loadDatasetPart(pathValidation, validation, false); + loadDatasetPart(pathValidation, validation.back(), false); } Ptr GR_chalearn::create() diff --git a/modules/datasetstools/src/gr_skig.cpp b/modules/datasetstools/src/gr_skig.cpp index aeecba7b62..fe783fd373 100644 --- a/modules/datasetstools/src/gr_skig.cpp +++ b/modules/datasetstools/src/gr_skig.cpp @@ -55,13 +55,13 @@ class CV_EXPORTS GR_skigImp : public GR_skig { public: GR_skigImp() {} - //GR_skigImp(const std::string &path); + //GR_skigImp(const string &path); virtual ~GR_skigImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*GR_skigImp::GR_skigImp(const string &path) @@ -69,18 +69,17 @@ class CV_EXPORTS GR_skigImp : public GR_skig loadDataset(path); }*/ -void GR_skigImp::load(const string &path, int number) +void GR_skigImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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]; @@ -117,7 +116,7 @@ void GR_skigImp::loadDataset(const string &path) curr->pose = (poseType)atoi( file.substr(posPose + strlen("pose_"), 1).c_str() ); curr->type = (actionType)atoi( file.substr(posType + strlen("actionType_"), 2).c_str() ); - train.push_back(curr); + train.back().push_back(curr); } else { printf("incorrect file name: %s", file.c_str()); diff --git a/modules/datasetstools/src/hpe_parse.cpp b/modules/datasetstools/src/hpe_parse.cpp index dab81512fe..ea835fdc1d 100644 --- a/modules/datasetstools/src/hpe_parse.cpp +++ b/modules/datasetstools/src/hpe_parse.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS HPE_parseImp : public HPE_parse { public: HPE_parseImp() {} - //HPE_parseImp(const std::string &path); + //HPE_parseImp(const string &path); virtual ~HPE_parseImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*HPE_parseImp::HPE_parseImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS HPE_parseImp : public HPE_parse loadDataset(path); }*/ -void HPE_parseImp::load(const string &path, int number) +void HPE_parseImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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); @@ -97,10 +96,10 @@ void HPE_parseImp::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; } diff --git a/modules/datasetstools/src/ir_affine.cpp b/modules/datasetstools/src/ir_affine.cpp index 7923284e2b..94a8a9a551 100644 --- a/modules/datasetstools/src/ir_affine.cpp +++ b/modules/datasetstools/src/ir_affine.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS IR_affineImp : public IR_affine { public: IR_affineImp() {} - //IR_affineImp(const std::string &path); + //IR_affineImp(const string &path); virtual ~IR_affineImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*IR_affineImp::IR_affineImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS IR_affineImp : public IR_affine loadDataset(path); }*/ -void IR_affineImp::load(const string &path, int number) +void IR_affineImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(path); } void IR_affineImp::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) { Ptr curr(new IR_affineObj); @@ -100,7 +99,7 @@ void IR_affineImp::loadDataset(const string &path) } } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/ir_robot.cpp b/modules/datasetstools/src/ir_robot.cpp index 71b0c33ff0..e9c0678f5c 100644 --- a/modules/datasetstools/src/ir_robot.cpp +++ b/modules/datasetstools/src/ir_robot.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS IR_robotImp : public IR_robot { public: IR_robotImp() {} - //IR_robotImp(const std::string &path); + //IR_robotImp(const string &path); virtual ~IR_robotImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*IR_robotImp::IR_robotImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS IR_robotImp : public IR_robot loadDataset(path); }*/ -void IR_robotImp::load(const string &path, int number) +void IR_robotImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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) @@ -95,7 +94,7 @@ void IR_robotImp::loadDataset(const string &path) string &fileName = *itScene; int imageNum = atoi( fileName.substr(3, 3).c_str() ); - int pos = atoi( fileName.substr(6, 2).c_str() ); + //int pos = atoi( fileName.substr(6, 2).c_str() ); if (imageNum != currImageNum) { curr->pos.push_back(cameraPos()); @@ -105,7 +104,7 @@ void IR_robotImp::loadDataset(const string &path) curr->pos.back().images.push_back(fileName); } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/is_bsds.cpp b/modules/datasetstools/src/is_bsds.cpp index 13a723e458..ebc397e307 100644 --- a/modules/datasetstools/src/is_bsds.cpp +++ b/modules/datasetstools/src/is_bsds.cpp @@ -53,15 +53,15 @@ class CV_EXPORTS IS_bsdsImp : public IS_bsds { public: IS_bsdsImp() {} - //IS_bsdsImp(const std::string &path); + //IS_bsdsImp(const string &path); virtual ~IS_bsdsImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); - void loadDatasetPart(const std::string &fileName, std::vector< Ptr > &dataset_); + void loadDatasetPart(const string &fileName, vector< Ptr > &dataset_); }; void IS_bsdsImp::loadDatasetPart(const string &fileName, vector< Ptr > &dataset_) @@ -81,26 +81,25 @@ void IS_bsdsImp::loadDatasetPart(const string &fileName, vector< Ptr > & loadDataset(path); }*/ -void IS_bsdsImp::load(const string &path, int number) +void IS_bsdsImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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() diff --git a/modules/datasetstools/src/is_weizmann.cpp b/modules/datasetstools/src/is_weizmann.cpp index ca2d7c5475..094521080e 100644 --- a/modules/datasetstools/src/is_weizmann.cpp +++ b/modules/datasetstools/src/is_weizmann.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS IS_weizmannImp : public IS_weizmann { public: IS_weizmannImp() {} - //IS_weizmannImp(const std::string &path); + //IS_weizmannImp(const string &path); virtual ~IS_weizmannImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*IS_weizmannImp::IS_weizmannImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS IS_weizmannImp : public IS_weizmann loadDataset(path); }*/ -void IS_weizmannImp::load(const string &path, int number) +void IS_weizmannImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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) @@ -93,7 +92,7 @@ void IS_weizmannImp::loadDataset(const string &path) curr->humanSeg = imageName + "human_seg/"; - train.push_back(curr); + train.back().push_back(curr); } } } diff --git a/modules/datasetstools/src/msm_epfl.cpp b/modules/datasetstools/src/msm_epfl.cpp index 798b5f97ec..220691e0c7 100644 --- a/modules/datasetstools/src/msm_epfl.cpp +++ b/modules/datasetstools/src/msm_epfl.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS MSM_epflImp : public MSM_epfl { public: MSM_epflImp() {} - //MSM_epflImp(const std::string &path); + //MSM_epflImp(const string &path); virtual ~MSM_epflImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*MSM_epflImp::MSM_epflImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS MSM_epflImp : public MSM_epfl loadDataset(path); }*/ -void MSM_epflImp::load(const string &path, int number) +void MSM_epflImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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/"); @@ -144,7 +143,7 @@ void MSM_epflImp::loadDataset(const string &path) } } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/msm_middlebury.cpp b/modules/datasetstools/src/msm_middlebury.cpp index 88a817233c..e65b1330f4 100644 --- a/modules/datasetstools/src/msm_middlebury.cpp +++ b/modules/datasetstools/src/msm_middlebury.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS MSM_middleburyImp : public MSM_middlebury { public: MSM_middleburyImp() {} - //MSM_middleburyImp(const std::string &path); + //MSM_middleburyImp(const string &path); virtual ~MSM_middleburyImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*MSM_middleburyImp::MSM_middleburyImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS MSM_middleburyImp : public MSM_middlebury loadDataset(path); }*/ -void MSM_middleburyImp::load(const string &path, int number) +void MSM_middleburyImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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); @@ -113,7 +112,7 @@ void MSM_middleburyImp::loadDataset(const string &path) infile >> curr->t[i]; } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/or_imagenet.cpp b/modules/datasetstools/src/or_imagenet.cpp index 6f327c959b..dc5986a4d4 100644 --- a/modules/datasetstools/src/or_imagenet.cpp +++ b/modules/datasetstools/src/or_imagenet.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS OR_imagenetImp : public OR_imagenet { public: OR_imagenetImp() {} - //OR_imagenetImp(const std::string &path); + //OR_imagenetImp(const string &path); virtual ~OR_imagenetImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*OR_imagenetImp::OR_imagenetImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS OR_imagenetImp : public OR_imagenet loadDataset(path); }*/ -void OR_imagenetImp::load(const string &path, int number) +void OR_imagenetImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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)) @@ -96,7 +95,7 @@ void OR_imagenetImp::loadDataset(const string &path) curr->wnid = elems[0]; curr->id2 = atoi(elems[1].c_str()); - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/or_sun.cpp b/modules/datasetstools/src/or_sun.cpp index c332617dd5..3a3492da5c 100644 --- a/modules/datasetstools/src/or_sun.cpp +++ b/modules/datasetstools/src/or_sun.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS OR_sunImp : public OR_sun { public: OR_sunImp() {} - //OR_sunImp(const std::string &path); + //OR_sunImp(const string &path); virtual ~OR_sunImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*OR_sunImp::OR_sunImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS OR_sunImp : public OR_sun loadDataset(path); }*/ -void OR_sunImp::load(const string &path, int number) +void OR_sunImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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; @@ -95,7 +94,7 @@ void OR_sunImp::loadDataset(const string &path) curr->imageNames.push_back(*it); } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/slam_kitti.cpp b/modules/datasetstools/src/slam_kitti.cpp index 6414d25b74..697889fd39 100644 --- a/modules/datasetstools/src/slam_kitti.cpp +++ b/modules/datasetstools/src/slam_kitti.cpp @@ -53,13 +53,13 @@ class CV_EXPORTS SLAM_kittiImp : public SLAM_kitti { public: SLAM_kittiImp() {} - //SLAM_kittiImp(const std::string &path); + //SLAM_kittiImp(const string &path); virtual ~SLAM_kittiImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*SLAM_kittiImp::SLAM_kittiImp(const string &path) @@ -67,18 +67,17 @@ class CV_EXPORTS SLAM_kittiImp : public SLAM_kitti loadDataset(path); }*/ -void SLAM_kittiImp::load(const string &path, int number) +void SLAM_kittiImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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); @@ -155,7 +154,7 @@ void SLAM_kittiImp::loadDataset(const string &path) curr->posesArray.push_back(p); } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/slam_tumindoor.cpp b/modules/datasetstools/src/slam_tumindoor.cpp index 85dbc56357..27712ebae2 100644 --- a/modules/datasetstools/src/slam_tumindoor.cpp +++ b/modules/datasetstools/src/slam_tumindoor.cpp @@ -55,13 +55,13 @@ class CV_EXPORTS SLAM_tumindoorImp : public SLAM_tumindoor { public: SLAM_tumindoorImp() {} - //SLAM_tumindoorImp(const std::string &path); + //SLAM_tumindoorImp(const string &path); virtual ~SLAM_tumindoorImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); }; /*SLAM_tumindoorImp::SLAM_tumindoorImp(const string &path) @@ -69,18 +69,17 @@ class CV_EXPORTS SLAM_tumindoorImp : public SLAM_tumindoor loadDataset(path); }*/ -void SLAM_tumindoorImp::load(const string &path, int number) +void SLAM_tumindoorImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(path); } void SLAM_tumindoorImp::loadDataset(const string &path) { + 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 @@ -138,7 +137,7 @@ void SLAM_tumindoorImp::loadDataset(const string &path) } } - train.push_back(curr); + train.back().push_back(curr); } } diff --git a/modules/datasetstools/src/tr_chars.cpp b/modules/datasetstools/src/tr_chars.cpp index b157e9207a..0760f0f785 100644 --- a/modules/datasetstools/src/tr_chars.cpp +++ b/modules/datasetstools/src/tr_chars.cpp @@ -56,10 +56,12 @@ class CV_EXPORTS TR_charsImp : public TR_chars //TR_charsImp(const string &path, int number = 0); virtual ~TR_charsImp() {} - virtual void load(const string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const string &path, int number = 0); + void loadDatasetSplit(const string &path, int number); + + void loadDataset(const string &path); void parseLine(const string &line, vector &currSet, int number); @@ -84,7 +86,7 @@ void TR_charsImp::parseLine(const string &line, vector &currSet, int number } } -inline void TR_charsImp::convert(vector &from, std::vector< Ptr > &to, vector &allLabels, vector &allNames) +inline void TR_charsImp::convert(vector &from, vector< Ptr > &to, vector &allLabels, vector &allNames) { for (vector::iterator it=from.begin(); it!=from.end(); ++it) { @@ -121,13 +123,31 @@ inline void TR_charsImp::parseSet(const string &line, const string &pattern, boo loadDataset(path, number); }*/ -void TR_charsImp::load(const string &path, int number) +void TR_charsImp::load(const string &path) { - loadDataset(path, number); + 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_charsImp::loadDataset(const string &path, int number) +void TR_charsImp::loadDatasetSplit(const string &path, int number) { + train.push_back(vector< Ptr >()); + test.push_back(vector< Ptr >()); + validation.push_back(vector< Ptr >()); + vector allLabels, trainSet, testSet, validationSet; vector allNames; @@ -189,9 +209,9 @@ void TR_charsImp::loadDataset(const string &path, int number) "list.TXNind = ["*/ } - convert(trainSet, train, allLabels, allNames); - convert(testSet, test, allLabels, allNames); - convert(validationSet, validation, allLabels, allNames); + convert(trainSet, train.back(), allLabels, allNames); + convert(testSet, test.back(), allLabels, allNames); + convert(validationSet, validation.back(), allLabels, allNames); } Ptr TR_chars::create() diff --git a/modules/datasetstools/src/tr_svt.cpp b/modules/datasetstools/src/tr_svt.cpp index 6a3b9db8a6..34d7fa908c 100644 --- a/modules/datasetstools/src/tr_svt.cpp +++ b/modules/datasetstools/src/tr_svt.cpp @@ -56,15 +56,15 @@ class CV_EXPORTS TR_svtImp : public TR_svt { public: TR_svtImp() {} - //TR_svtImp(const std::string &path); + //TR_svtImp(const string &path); virtual ~TR_svtImp() {} - virtual void load(const std::string &path, int number = 0); + virtual void load(const string &path); private: - void loadDataset(const std::string &path); + void loadDataset(const string &path); - void xmlParse(const std::string &set, std::vector< Ptr > &out); + void xmlParse(const string &set, vector< Ptr > &out); }; void TR_svtImp::xmlParse(const string &set, vector< Ptr > &out) @@ -117,26 +117,25 @@ void TR_svtImp::xmlParse(const string &set, vector< Ptr > &out) loadDataset(path); }*/ -void TR_svtImp::load(const string &path, int number) +void TR_svtImp::load(const string &path) { - if (number!=0) - { - return; - } - loadDataset(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() From 4000b35dbe70e1b9b17ecb8ec7045262540846cf Mon Sep 17 00:00:00 2001 From: Dmitriy Anisimov Date: Sat, 6 Sep 2014 11:05:07 +0400 Subject: [PATCH 4/8] minor changes & fixed win64 warning --- .../include/opencv2/datasetstools/dataset.hpp | 11 ++- modules/datasetstools/samples/ar_hmdb.cpp | 2 +- modules/datasetstools/src/dataset.cpp | 89 +++++++++++++++++++ 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 modules/datasetstools/src/dataset.cpp diff --git a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp index a12be84804..9cb1e7381d 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/dataset.hpp @@ -64,16 +64,19 @@ class CV_EXPORTS Dataset virtual void load(const std::string &path) = 0; - std::vector< Ptr >& getTrain(int splitNum = 0) { return train[splitNum]; } - std::vector< Ptr >& getTest(int splitNum = 0) { return test[splitNum]; } - std::vector< Ptr >& getValidation(int splitNum = 0) { return validation[splitNum]; } + std::vector< Ptr >& getTrain(int splitNum = 0); + std::vector< Ptr >& getTest(int splitNum = 0); + std::vector< Ptr >& getValidation(int splitNum = 0); - int getNumSplits() const { return train.size(); } + 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/samples/ar_hmdb.cpp b/modules/datasetstools/samples/ar_hmdb.cpp index b45297cc3c..9835727464 100644 --- a/modules/datasetstools/samples/ar_hmdb.cpp +++ b/modules/datasetstools/samples/ar_hmdb.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) // 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->getTrain()[0].get()); + 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/src/dataset.cpp b/modules/datasetstools/src/dataset.cpp new file mode 100644 index 0000000000..9473f2aa34 --- /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(); +} + +} +} + From 5624ad2c8e38af58589f6e9f74c9e5d7dff9dd38 Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Tue, 9 Sep 2014 18:47:10 +0400 Subject: [PATCH 5/8] slight updated ir_affine --- modules/datasetstools/CMakeLists.txt | 2 +- modules/datasetstools/src/ir_affine.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/datasetstools/CMakeLists.txt b/modules/datasetstools/CMakeLists.txt index 3e058a5a7e..933974415b 100644 --- a/modules/datasetstools/CMakeLists.txt +++ b/modules/datasetstools/CMakeLists.txt @@ -1,3 +1,3 @@ set(the_description "datasets tools") -ocv_define_module(datasetstools opencv_core) +ocv_define_module(datasetstools opencv_core opencv_features2d) diff --git a/modules/datasetstools/src/ir_affine.cpp b/modules/datasetstools/src/ir_affine.cpp index 94a8a9a551..3373ecd15f 100644 --- a/modules/datasetstools/src/ir_affine.cpp +++ b/modules/datasetstools/src/ir_affine.cpp @@ -78,13 +78,27 @@ void IR_affineImp::loadDataset(const string &path) 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) { From 4041650fc4191c3eba36aee0c554f1e4bca3c65c Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Fri, 12 Sep 2014 15:15:02 +0400 Subject: [PATCH 6/8] updated fr_lfw dataset loader --- modules/datasetstools/doc/datasetstools.rst | 6 +- .../include/opencv2/datasetstools/fr_lfw.hpp | 4 +- modules/datasetstools/samples/ar_hmdb.cpp | 3 + modules/datasetstools/samples/fr_lfw.cpp | 25 ++++--- modules/datasetstools/src/fr_lfw.cpp | 65 ++++++++++++++++--- modules/xfeatures2d/CMakeLists.txt | 2 +- 6 files changed, 80 insertions(+), 25 deletions(-) diff --git a/modules/datasetstools/doc/datasetstools.rst b/modules/datasetstools/doc/datasetstools.rst index acdc3a5602..193c17ca0f 100644 --- a/modules/datasetstools/doc/datasetstools.rst +++ b/modules/datasetstools/doc/datasetstools.rst @@ -50,13 +50,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/ diff --git a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp index 1fcdd3a42f..dbc0a499a2 100644 --- a/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp +++ b/modules/datasetstools/include/opencv2/datasetstools/fr_lfw.hpp @@ -56,8 +56,8 @@ 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 diff --git a/modules/datasetstools/samples/ar_hmdb.cpp b/modules/datasetstools/samples/ar_hmdb.cpp index 9835727464..5bb067f43c 100644 --- a/modules/datasetstools/samples/ar_hmdb.cpp +++ b/modules/datasetstools/samples/ar_hmdb.cpp @@ -72,6 +72,9 @@ int main(int argc, char *argv[]) // 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. + 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; diff --git a/modules/datasetstools/samples/fr_lfw.cpp b/modules/datasetstools/samples/fr_lfw.cpp index 51463ef413..348c696660 100644 --- a/modules/datasetstools/samples/fr_lfw.cpp +++ b/modules/datasetstools/samples/fr_lfw.cpp @@ -69,16 +69,21 @@ int main(int argc, char *argv[]) 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->getTrain().size()); - FR_lfwObj *example = static_cast(dataset->getTrain()[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/src/fr_lfw.cpp b/modules/datasetstools/src/fr_lfw.cpp index 0c9f506fab..420bd91434 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 @@ -60,6 +62,8 @@ class CV_EXPORTS FR_lfwImp : public FR_lfw private: void loadDataset(const string &path); + + map< string, vector > faces; }; /*FR_lfwImp::FR_lfwImp(const string &path) @@ -74,26 +78,69 @@ void FR_lfwImp::load(const string &path) void FR_lfwImp::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) { - Ptr curr(new FR_lfwObj); - curr->name = *it; + if ("pairs.txt" == *it) + { + continue; + } - string pathFace(path + curr->name + "/"); + string &name = *it; + vector images; + + 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.back().push_back(curr); + faces.insert(make_pair(name, images)); + } + + // test loading + ifstream infile((path + "pairs.txt").c_str()); + string line; + getline(infile, line); // should be 10 300 + unsigned int num = 0; + while (getline(infile, line)) + { + if (0 == (num % 600)) + { + train.push_back(vector< Ptr >()); + 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++; } } diff --git a/modules/xfeatures2d/CMakeLists.txt b/modules/xfeatures2d/CMakeLists.txt index 63b4240e54..0f3ac76344 100644 --- a/modules/xfeatures2d/CMakeLists.txt +++ b/modules/xfeatures2d/CMakeLists.txt @@ -1,2 +1,2 @@ set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection") -ocv_define_module(xfeatures2d opencv_core opencv_cudaarithm opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml) +ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml opencv_cudaarithm) From 9ee9f182d672d8739dc0cecd06905d1c4298d09f Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Fri, 12 Sep 2014 15:20:27 +0400 Subject: [PATCH 7/8] minor CMakeLists cleaning --- modules/datasetstools/CMakeLists.txt | 2 +- modules/xfeatures2d/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datasetstools/CMakeLists.txt b/modules/datasetstools/CMakeLists.txt index 933974415b..3e058a5a7e 100644 --- a/modules/datasetstools/CMakeLists.txt +++ b/modules/datasetstools/CMakeLists.txt @@ -1,3 +1,3 @@ set(the_description "datasets tools") -ocv_define_module(datasetstools opencv_core opencv_features2d) +ocv_define_module(datasetstools opencv_core) diff --git a/modules/xfeatures2d/CMakeLists.txt b/modules/xfeatures2d/CMakeLists.txt index 0f3ac76344..63b4240e54 100644 --- a/modules/xfeatures2d/CMakeLists.txt +++ b/modules/xfeatures2d/CMakeLists.txt @@ -1,2 +1,2 @@ set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection") -ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml opencv_cudaarithm) +ocv_define_module(xfeatures2d opencv_core opencv_cudaarithm opencv_imgproc opencv_features2d opencv_calib3d opencv_shape opencv_highgui opencv_videoio opencv_ml) From ee12bc12f2bd4653845886e1fe56483c042dbc61 Mon Sep 17 00:00:00 2001 From: "dmitriy.anisimov" Date: Mon, 15 Sep 2014 13:33:49 +0400 Subject: [PATCH 8/8] added MNIST dataset loader --- modules/datasetstools/doc/datasetstools.rst | 18 ++- .../opencv2/datasetstools/or_mnist.hpp | 74 +++++++++ modules/datasetstools/samples/or_mnist.cpp | 89 +++++++++++ modules/datasetstools/src/or_mnist.cpp | 142 ++++++++++++++++++ 4 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 modules/datasetstools/include/opencv2/datasetstools/or_mnist.hpp create mode 100644 modules/datasetstools/samples/or_mnist.cpp create mode 100644 modules/datasetstools/src/or_mnist.cpp diff --git a/modules/datasetstools/doc/datasetstools.rst b/modules/datasetstools/doc/datasetstools.rst index 193c17ca0f..f2b0ae71f8 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 ------------------ @@ -241,6 +239,22 @@ 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 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 0000000000..89763c5ee7 --- /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/samples/or_mnist.cpp b/modules/datasetstools/samples/or_mnist.cpp new file mode 100644 index 0000000000..cb776ba43e --- /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/src/or_mnist.cpp b/modules/datasetstools/src/or_mnist.cpp new file mode 100644 index 0000000000..5fe3122138 --- /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); +} + +} +}