gr_chalearn.cpp 6.02 KB
Newer Older
dmitriy.anisimov's avatar
dmitriy.anisimov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*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*/

42
#include "opencv2/datasets/gr_chalearn.hpp"
43
#include "opencv2/datasets/util.hpp"
dmitriy.anisimov's avatar
dmitriy.anisimov committed
44

45 46
namespace cv
{
47
namespace datasets
48 49
{

dmitriy.anisimov's avatar
dmitriy.anisimov committed
50 51
using namespace std;

Dmitriy Anisimov's avatar
Dmitriy Anisimov committed
52
class GR_chalearnImp : public GR_chalearn
53 54 55
{
public:
    GR_chalearnImp() {}
56
    //GR_chalearnImp(const string &path);
57 58
    virtual ~GR_chalearnImp() {}

59
    virtual void load(const string &path);
60 61

private:
62
    void loadDataset(const string &path);
dmitriy.anisimov's avatar
dmitriy.anisimov committed
63

64
    void loadDatasetPart(const string &path, vector< Ptr<Object> > &dataset_, bool loadLabels);
65 66 67
};

/*GR_chalearnImp::GR_chalearnImp(const string &path)
dmitriy.anisimov's avatar
dmitriy.anisimov committed
68 69
{
    loadDataset(path);
70
}*/
dmitriy.anisimov's avatar
dmitriy.anisimov committed
71

72
void GR_chalearnImp::load(const string &path)
73 74 75 76
{
    loadDataset(path);
}

dmitriy.anisimov's avatar
dmitriy.anisimov committed
77
void GR_chalearnImp::loadDatasetPart(const string &path, vector< Ptr<Object> > &dataset_, bool loadLabels)
dmitriy.anisimov's avatar
dmitriy.anisimov committed
78 79 80 81 82
{
    vector<string> fileNames;
    getDirList(path, fileNames);
    for (vector<string>::iterator it=fileNames.begin(); it!=fileNames.end(); ++it)
    {
83
        Ptr<GR_chalearnObj> curr(new GR_chalearnObj);
84 85 86 87
        curr->name = *it;
        curr->nameColor = curr->name + "/" + curr->name + "_color.mp4";
        curr->nameDepth = curr->name + "/" + curr->name + "_depth.mp4";
        curr->nameUser = curr->name + "/" + curr->name + "_user.mp4";
dmitriy.anisimov's avatar
dmitriy.anisimov committed
88 89

        // loading video info
90
        string fileVideoInfo(path + curr->name + "/" + curr->name + "_data.csv");
dmitriy.anisimov's avatar
dmitriy.anisimov committed
91 92 93 94 95
        ifstream infile(fileVideoInfo.c_str());
        string line;
        getline(infile, line);
        vector<string> elems;
        split(line, elems, ',');
96 97 98
        curr->numFrames = atoi(elems[0].c_str());
        curr->fps = atoi(elems[1].c_str());
        curr->depth = atoi(elems[2].c_str());
dmitriy.anisimov's avatar
dmitriy.anisimov committed
99 100

        // loading ground truth
dmitriy.anisimov's avatar
dmitriy.anisimov committed
101
        if (loadLabels)
dmitriy.anisimov's avatar
dmitriy.anisimov committed
102
        {
dmitriy.anisimov's avatar
dmitriy.anisimov committed
103 104 105 106 107 108
            string fileGroundTruth(path + curr->name + "/" + curr->name + "_labels.csv");
            ifstream infileGroundTruth(fileGroundTruth.c_str());
            while (getline(infileGroundTruth, line))
            {
                vector<string> elems2;
                split(line, elems2, ',');
dmitriy.anisimov's avatar
dmitriy.anisimov committed
109

dmitriy.anisimov's avatar
dmitriy.anisimov committed
110 111 112 113
                groundTruth currGroundTruth;
                currGroundTruth.gestureID = atoi(elems2[0].c_str());
                currGroundTruth.initialFrame = atoi(elems2[1].c_str());
                currGroundTruth.lastFrame = atoi(elems2[2].c_str());
dmitriy.anisimov's avatar
dmitriy.anisimov committed
114

dmitriy.anisimov's avatar
dmitriy.anisimov committed
115 116
                curr->groundTruths.push_back(currGroundTruth);
            }
dmitriy.anisimov's avatar
dmitriy.anisimov committed
117 118 119
        }

        // loading skeleton
120
        string fileSkeleton(path + curr->name + "/" + curr->name + "_skeleton.csv");
dmitriy.anisimov's avatar
dmitriy.anisimov committed
121 122 123 124 125
        ifstream infileSkeleton(fileSkeleton.c_str());
        while (getline(infileSkeleton, line))
        {
            skeleton currSkeleton;

126 127
            vector<string> elems2;
            split(line, elems2, ',');
dmitriy.anisimov's avatar
dmitriy.anisimov committed
128

129
            for (unsigned int i=0, numJoin=0; i<elems2.size(); i+=9, ++numJoin)
dmitriy.anisimov's avatar
dmitriy.anisimov committed
130
            {
131 132 133 134 135 136 137 138 139
                currSkeleton.s[numJoin].Wx = atof(elems2[i+0].c_str());
                currSkeleton.s[numJoin].Wy = atof(elems2[i+1].c_str());
                currSkeleton.s[numJoin].Wz = atof(elems2[i+2].c_str());
                currSkeleton.s[numJoin].Rx = atof(elems2[i+3].c_str());
                currSkeleton.s[numJoin].Ry = atof(elems2[i+4].c_str());
                currSkeleton.s[numJoin].Rz = atof(elems2[i+5].c_str());
                currSkeleton.s[numJoin].Rw = atof(elems2[i+6].c_str());
                currSkeleton.s[numJoin].Px = atof(elems2[i+7].c_str());
                currSkeleton.s[numJoin].Py = atof(elems2[i+8].c_str());
dmitriy.anisimov's avatar
dmitriy.anisimov committed
140 141
            }

142
            curr->skeletons.push_back(currSkeleton);
dmitriy.anisimov's avatar
dmitriy.anisimov committed
143 144
        }

dmitriy.anisimov's avatar
dmitriy.anisimov committed
145
        dataset_.push_back(curr);
dmitriy.anisimov's avatar
dmitriy.anisimov committed
146 147
    }
}
148

dmitriy.anisimov's avatar
dmitriy.anisimov committed
149 150
void GR_chalearnImp::loadDataset(const string &path)
{
151 152 153 154
    train.push_back(vector< Ptr<Object> >());
    test.push_back(vector< Ptr<Object> >());
    validation.push_back(vector< Ptr<Object> >());

dmitriy.anisimov's avatar
dmitriy.anisimov committed
155
    string pathTrain(path + "Train/");
156
    loadDatasetPart(pathTrain, train.back(), true);
dmitriy.anisimov's avatar
dmitriy.anisimov committed
157 158 159

    // freely available validation set doesn't have labels
    string pathValidation(path + "Validation/");
160
    loadDatasetPart(pathValidation, validation.back(), false);
dmitriy.anisimov's avatar
dmitriy.anisimov committed
161 162
}

163 164 165 166 167
Ptr<GR_chalearn> GR_chalearn::create()
{
    return Ptr<GR_chalearnImp>(new GR_chalearnImp);
}

168 169
}
}