vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*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/datasets/ar_hmdb.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<AR_hmdb> 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.
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
printf("train 1 size: %u\n", (unsigned int)dataset->getTrain(1).size());
|
||||
printf("test 1 size: %u\n", (unsigned int)dataset->getTest(1).size());
|
||||
|
||||
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(dataset->getTrain(1)[0].get());
|
||||
printf("first image:\n");
|
||||
printf("action id: %u\n", example->id);
|
||||
printf("action: %s\n", example->name.c_str());
|
||||
printf("file: %s\n", example->videoName.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/*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/datasets/ar_hmdb.hpp"
|
||||
#include "opencv2/datasets/util.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/flann.hpp>
|
||||
#include <opencv2/ml.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
using namespace cv::flann;
|
||||
using namespace cv::ml;
|
||||
|
||||
void fillData(const string &path, vector< Ptr<Object> > &curr, Index &flann_index, Mat1f &data, Mat1i &labels);
|
||||
void fillData(const string &path, vector< Ptr<Object> > &curr, Index &flann_index, Mat1f &data, Mat1i &labels)
|
||||
{
|
||||
const unsigned int descriptorNum = 162;
|
||||
Mat1f sample(1, descriptorNum);
|
||||
Mat1i nresps(1, 1);
|
||||
Mat1f dists(1, 1);
|
||||
|
||||
unsigned int numFiles = 0;
|
||||
for (unsigned int i=0; i<curr.size(); ++i)
|
||||
{
|
||||
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(curr[i].get());
|
||||
string featuresFullPath = path + "hmdb51_org_stips/" + example->name + "/" + example->videoName + ".txt";
|
||||
|
||||
ifstream infile(featuresFullPath.c_str());
|
||||
string line;
|
||||
// skip header
|
||||
for (unsigned int j=0; j<3; ++j)
|
||||
{
|
||||
getline(infile, line);
|
||||
}
|
||||
while (getline(infile, line))
|
||||
{
|
||||
// 7 skip, hog+hof: 72+90 read
|
||||
vector<string> elems;
|
||||
split(line, elems, '\t');
|
||||
|
||||
for (unsigned int j=0; j<descriptorNum; ++j)
|
||||
{
|
||||
sample(0, j) = (float)atof(elems[j+7].c_str());
|
||||
}
|
||||
|
||||
flann_index.knnSearch(sample, nresps, dists, 1, SearchParams());
|
||||
data(numFiles, nresps(0, 0)) ++;
|
||||
}
|
||||
labels(numFiles, 0) = example->id;
|
||||
numFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading dataset
|
||||
Ptr<AR_hmdb> dataset = AR_hmdb::create();
|
||||
dataset->load(path);
|
||||
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
|
||||
|
||||
const unsigned int descriptorNum = 162;
|
||||
const unsigned int clusterNum = 4000;
|
||||
const unsigned int sampleNum = 5613856; // max for all 3 splits
|
||||
|
||||
vector<double> res;
|
||||
for (int currSplit=0; currSplit<numSplits; ++currSplit)
|
||||
{
|
||||
Mat1f samples(sampleNum, descriptorNum);
|
||||
unsigned int currSample = 0;
|
||||
vector< Ptr<Object> > &curr = dataset->getTrain(currSplit);
|
||||
unsigned int numFeatures = 0;
|
||||
for (unsigned int i=0; i<curr.size(); ++i)
|
||||
{
|
||||
AR_hmdbObj *example = static_cast<AR_hmdbObj *>(curr[i].get());
|
||||
string featuresFullPath = path + "hmdb51_org_stips/" + example->name + "/" + example->videoName + ".txt";
|
||||
ifstream infile(featuresFullPath.c_str());
|
||||
string line;
|
||||
// skip header
|
||||
for (unsigned int j=0; j<3; ++j)
|
||||
{
|
||||
getline(infile, line);
|
||||
}
|
||||
while (getline(infile, line))
|
||||
{
|
||||
numFeatures++;
|
||||
if (currSample < sampleNum)
|
||||
{
|
||||
// 7 skip, hog+hof: 72+90 read
|
||||
vector<string> elems;
|
||||
split(line, elems, '\t');
|
||||
|
||||
for (unsigned int j=0; j<descriptorNum; ++j)
|
||||
{
|
||||
samples(currSample, j) = (float)atof(elems[j+7].c_str());
|
||||
}
|
||||
currSample++;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("split %u, train features number: %u, samples number: %u\n", currSplit, numFeatures, currSample);
|
||||
|
||||
// clustering
|
||||
Mat1f centers(clusterNum, descriptorNum);
|
||||
::cvflann::KMeansIndexParams kmean_params;
|
||||
unsigned int resultClusters = hierarchicalClustering< L2<float> >(samples, centers, kmean_params);
|
||||
if (resultClusters < clusterNum)
|
||||
{
|
||||
centers = centers.rowRange(Range(0, resultClusters));
|
||||
}
|
||||
Index flann_index(centers, KDTreeIndexParams());
|
||||
printf("resulted clusters number: %u\n", resultClusters);
|
||||
|
||||
|
||||
unsigned int numTrainFiles = curr.size();
|
||||
Mat1f trainData(numTrainFiles, resultClusters);
|
||||
Mat1i trainLabels(numTrainFiles, 1);
|
||||
|
||||
for (unsigned int i=0; i<numTrainFiles; ++i)
|
||||
{
|
||||
for (unsigned int j=0; j<resultClusters; ++j)
|
||||
{
|
||||
trainData(i, j) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf("calculating train histograms\n");
|
||||
fillData(path, curr, flann_index, trainData, trainLabels);
|
||||
|
||||
printf("train svm\n");
|
||||
Ptr<SVM> svm = SVM::create();
|
||||
svm->setType(SVM::C_SVC);
|
||||
svm->setKernel(SVM::POLY); //SVM::RBF;
|
||||
svm->setDegree(0.5);
|
||||
svm->setGamma(1);
|
||||
svm->setCoef0(1);
|
||||
svm->setC(1);
|
||||
svm->setNu(0.5);
|
||||
svm->setP(0);
|
||||
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 1000, 0.01));
|
||||
svm->train(trainData, ROW_SAMPLE, trainLabels);
|
||||
|
||||
// prepare to predict
|
||||
curr = dataset->getTest(currSplit);
|
||||
unsigned int numTestFiles = curr.size();
|
||||
Mat1f testData(numTestFiles, resultClusters);
|
||||
Mat1i testLabels(numTestFiles, 1); // ground true
|
||||
|
||||
for (unsigned int i=0; i<numTestFiles; ++i)
|
||||
{
|
||||
for (unsigned int j=0; j<resultClusters; ++j)
|
||||
{
|
||||
testData(i, j) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf("calculating test histograms\n");
|
||||
fillData(path, curr, flann_index, testData, testLabels);
|
||||
|
||||
printf("predicting\n");
|
||||
Mat1f testPredicted(numTestFiles, 1);
|
||||
svm->predict(testData, testPredicted);
|
||||
|
||||
unsigned int correct = 0;
|
||||
for (unsigned int i=0; i<numTestFiles; ++i)
|
||||
{
|
||||
if ((int)testPredicted(i, 0) == testLabels(i, 0))
|
||||
{
|
||||
correct++;
|
||||
}
|
||||
}
|
||||
double accuracy = 1.0*correct/numTestFiles;
|
||||
printf("correctly recognized actions: %f\n", accuracy);
|
||||
res.push_back(accuracy);
|
||||
}
|
||||
|
||||
double accuracy = 0.0;
|
||||
for (unsigned int i=0; i<res.size(); ++i)
|
||||
{
|
||||
accuracy += res[i];
|
||||
}
|
||||
printf("average: %f\n", accuracy/res.size());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*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/datasets/ar_sports.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset description }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<AR_sports> 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->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
AR_sportsObj *example = static_cast<AR_sportsObj *>(dataset->getTest()[0].get());
|
||||
printf("url: %s\n", example->videoUrl.c_str());
|
||||
printf("labels: ");
|
||||
vector<int> &labels = example->labels;
|
||||
for (vector<int>::iterator it=labels.begin(); it!=labels.end(); ++it)
|
||||
{
|
||||
printf("%u ", *it);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*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/datasets/fr_adience.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folder and splits }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<FR_adience> dataset = FR_adience::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains for each object its images.
|
||||
// For example, let output splits number, dataset size and last image.
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
FR_adienceObj *example = static_cast<FR_adienceObj *>(dataset->getTrain().back().get());
|
||||
printf("last image:\n");
|
||||
printf("user_id: %s\n", example->user_id.c_str());
|
||||
printf("original_image: %s\n", example->original_image.c_str());
|
||||
printf("face_id: %u\n", example->face_id);
|
||||
printf("age: %s\n", example->age.c_str());
|
||||
printf("gender: ");
|
||||
if (example->gender == male)
|
||||
{
|
||||
printf("m\n");
|
||||
} else
|
||||
if (example->gender == female)
|
||||
{
|
||||
printf("f\n");
|
||||
} else
|
||||
{
|
||||
printf("none\n");
|
||||
}
|
||||
printf("x: %u\n", example->x);
|
||||
printf("y: %u\n", example->y);
|
||||
printf("dx: %u\n", example->dx);
|
||||
printf("dy: %u\n", example->dy);
|
||||
printf("tilt_ang: %d\n", example->tilt_ang);
|
||||
printf("fiducial_yaw_angle: %d\n", example->fiducial_yaw_angle);
|
||||
printf("fiducial_score: %u\n", example->fiducial_score);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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/datasets/fr_lfw.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (lfw2 folder) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<FR_lfw> dataset = FR_lfw::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// 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<FR_lfwObj *>(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<FR_lfwObj *>(dataset->getTest()[300].get());
|
||||
printf("300 test, first image: %s\n", example->image1.c_str());
|
||||
printf("300 test, second image: %s\n", example->image2.c_str());
|
||||
printf("300 test, same: %s\n", example->same?"yes":"no");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*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/core.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/datasets/fr_lfw.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (lfw2 folder) }"
|
||||
"{ train t |dev | train method: 'dev'(pairsDevTrain.txt) or 'split'(pairs.txt) }";
|
||||
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
string trainMethod(parser.get<string>("train"));
|
||||
|
||||
// our trained threshold for "same":
|
||||
double threshold = 0;
|
||||
|
||||
// load dataset
|
||||
Ptr<FR_lfw> dataset = FR_lfw::create();
|
||||
dataset->load(path);
|
||||
|
||||
unsigned int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
if (trainMethod == "dev")
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
else
|
||||
printf("train size: %u\n", (numSplits-1) * (unsigned int)dataset->getTest().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
|
||||
if (trainMethod == "dev") // train on personsDevTrain.txt
|
||||
{
|
||||
// collect average same-distances:
|
||||
double avg = 0;
|
||||
int count = 0;
|
||||
for (unsigned int i=0; i<dataset->getTrain().size(); ++i)
|
||||
{
|
||||
FR_lfwObj *example = static_cast<FR_lfwObj *>(dataset->getTrain()[i].get());
|
||||
|
||||
Mat a = imread(path+example->image1, IMREAD_GRAYSCALE);
|
||||
Mat b = imread(path+example->image2, IMREAD_GRAYSCALE);
|
||||
double dist = norm(a,b);
|
||||
if (example->same)
|
||||
{
|
||||
avg += dist;
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
threshold = avg / count;
|
||||
}
|
||||
|
||||
vector<double> p;
|
||||
for (unsigned int j=0; j<numSplits; ++j)
|
||||
{
|
||||
if (trainMethod == "split") // train on the remaining 9 splits from pairs.txt
|
||||
{
|
||||
double avg = 0;
|
||||
int count = 0;
|
||||
for (unsigned int j2=0; j2<numSplits; ++j2)
|
||||
{
|
||||
if (j==j2) continue; // skip test split for training
|
||||
|
||||
vector < Ptr<Object> > &curr = dataset->getTest(j2);
|
||||
for (unsigned int i=0; i<curr.size(); ++i)
|
||||
{
|
||||
FR_lfwObj *example = static_cast<FR_lfwObj *>(curr[i].get());
|
||||
Mat a = imread(path+example->image1, IMREAD_GRAYSCALE);
|
||||
Mat b = imread(path+example->image2, IMREAD_GRAYSCALE);
|
||||
double dist = norm(a,b);
|
||||
if (example->same)
|
||||
{
|
||||
avg += dist;
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
threshold = avg / count;
|
||||
}
|
||||
|
||||
unsigned int incorrect = 0, correct = 0;
|
||||
vector < Ptr<Object> > &curr = dataset->getTest(j);
|
||||
for (unsigned int i=0; i<curr.size(); ++i)
|
||||
{
|
||||
FR_lfwObj *example = static_cast<FR_lfwObj *>(curr[i].get());
|
||||
|
||||
Mat a = imread(path+example->image1, IMREAD_GRAYSCALE);
|
||||
Mat b = imread(path+example->image2, IMREAD_GRAYSCALE);
|
||||
bool same = (norm(a,b) <= threshold);
|
||||
if (same == example->same)
|
||||
correct++;
|
||||
else
|
||||
incorrect++;
|
||||
}
|
||||
p.push_back(1.0*correct/(correct+incorrect));
|
||||
printf("correct: %u, from: %u -> %f\n", correct, correct+incorrect, p.back());
|
||||
}
|
||||
|
||||
double mu = 0.0;
|
||||
for (vector<double>::iterator it=p.begin(); it!=p.end(); ++it)
|
||||
{
|
||||
mu += *it;
|
||||
}
|
||||
mu /= p.size();
|
||||
double sigma = 0.0;
|
||||
for (vector<double>::iterator it=p.begin(); it!=p.end(); ++it)
|
||||
{
|
||||
sigma += (*it - mu)*(*it - mu);
|
||||
}
|
||||
sigma = sqrt(sigma/p.size());
|
||||
double se = sigma/sqrt(double(p.size()));
|
||||
printf("estimated mean accuracy: %f and the standard error of the mean: %f\n", mu, se);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*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/datasets/gr_chalearn.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folder }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<GR_chalearn> dataset = GR_chalearn::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains information for each sample.
|
||||
// For example, let output dataset size and first element.
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
printf("validation size: %u\n", (unsigned int)dataset->getValidation().size());
|
||||
GR_chalearnObj *example = static_cast<GR_chalearnObj *>(dataset->getTrain()[0].get());
|
||||
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());
|
||||
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);
|
||||
for (vector<groundTruth>::iterator it=example->groundTruths.begin(); it!=example->groundTruths.end(); ++it)
|
||||
{
|
||||
printf("gestureID: %u, initial frame: %u, last frame: %u\n", (*it).gestureID, (*it).initialFrame, (*it).lastFrame);
|
||||
}
|
||||
printf("skeletons number: %u\n", (unsigned int)example->skeletons.size());
|
||||
skeleton &last = example->skeletons.back();
|
||||
printf("last skeleton:\n");
|
||||
for (unsigned int i=0; i<20; ++i)
|
||||
{
|
||||
printf("Wx: %f, Wy: %f, Wz: %f, Rx: %f, Ry: %f, Rz: %f, Rw: %f, Px: %f, Py: %f\n",
|
||||
last.s[i].Wx, last.s[i].Wy, last.s[i].Wz, last.s[i].Rx,
|
||||
last.s[i].Ry, last.s[i].Rz, last.s[i].Rw, last.s[i].Px, last.s[i].Py);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*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/datasets/gr_skig.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (subject* folders) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<GR_skig> 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<GR_skigObj *>(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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*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/datasets/hpe_humaneva.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folder }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (unsigned int i=1; i<=2; ++i)
|
||||
{
|
||||
printf("\tHumanEva %u\n", i);
|
||||
char number[2];
|
||||
sprintf(number, "%u", i);
|
||||
string pathCurr(path+"HumanEva_"+number+"/");
|
||||
|
||||
Ptr<HPE_humaneva> dataset = HPE_humaneva::create(i);
|
||||
dataset->load(pathCurr);
|
||||
|
||||
// ***************
|
||||
// dataset contains pair of rgb\dep images
|
||||
// For example, let output train size and last element.
|
||||
HPE_humanevaObj *example = static_cast<HPE_humanevaObj *>(dataset->getTrain().back().get());
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
printf("last train video:\n");
|
||||
printf("person: %u\n", example->person);
|
||||
printf("action: %s\n", example->action.c_str());
|
||||
printf("type1: %u\n", example->type1);
|
||||
printf("type2: %s\n", example->type2.c_str());
|
||||
printf("filename: %s\n", example->fileName.c_str());
|
||||
printf("num images: %u\n", (int)example->imageNames.size());
|
||||
printf("ofs:");
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf(" %f", example->ofs(0, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*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/datasets/hpe_parse.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (people_all folder) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<HPE_parse> 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->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
HPE_parseObj *example1 = static_cast<HPE_parseObj *>(dataset->getTrain()[0].get());
|
||||
HPE_parseObj *example2 = static_cast<HPE_parseObj *>(dataset->getTest()[0].get());
|
||||
printf("first train image: %s\n", example1->name.c_str());
|
||||
printf("first test image: %s\n", example2->name.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*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/datasets/ir_affine.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folder }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading dataset
|
||||
Ptr<IR_affine> 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->getTrain().size());
|
||||
|
||||
IR_affineObj *example = static_cast<IR_affineObj *>(dataset->getTrain().back().get());
|
||||
printf("image name: %s\n", example->imageName.c_str());
|
||||
printf("matrix:\n");
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf("%f ", example->mat(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*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/datasets/ir_robot.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folders }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<IR_robot> 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<IR_robotObj *>(dataset->getTrain().back().get());
|
||||
printf("last dataset object:\n");
|
||||
printf("name: %s\n", example->name.c_str());
|
||||
printf("number postitions: %u\n", (unsigned int)example->pos.size());
|
||||
string currPath(path + example->name + "/");
|
||||
|
||||
for (vector<cameraPos>::iterator itP=example->pos.begin(); itP!=example->pos.end(); ++itP)
|
||||
{
|
||||
for (vector<string>::iterator it=itP->images.begin(); it!=itP->images.end(); ++it)
|
||||
{
|
||||
printf("%s\n", (currPath+(*it)).c_str());
|
||||
}
|
||||
}
|
||||
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*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/datasets/is_bsds.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (images, iids_train.txt, iids_test.txt) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<IS_bsds> dataset = IS_bsds::create();
|
||||
dataset->load(path);
|
||||
|
||||
// TODO: read human/ folder for evaluation
|
||||
|
||||
// ***************
|
||||
// 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->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
IS_bsdsObj *example1 = static_cast<IS_bsdsObj *>(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<IS_bsdsObj *>(dataset->getTest()[0].get());
|
||||
fullPath = path + "images/test/" + example2->name + ".jpg";
|
||||
printf("first test image: %s\n", fullPath.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*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/datasets/is_weizmann.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (1obj/2obj folders) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<IS_weizmann> 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->getTrain().size());
|
||||
IS_weizmannObj *example = static_cast<IS_weizmannObj *>(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());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*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/datasets/msm_epfl.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (bounding/, camera/, P/, png/ folders) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<MSM_epfl> 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->getTrain().size());
|
||||
MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset->getTrain()[0].get());
|
||||
printf("first image:\nname: %s\n", example->imageName.c_str());
|
||||
|
||||
printf("\nbounding:\n");
|
||||
for (int i=0; i<2; ++i)
|
||||
{
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf("%f ", example->bounding(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\ncamera:\n");
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf("%f ", example->camera.mat1(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
printf("%f ", example->camera.mat2[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf("%f ", example->camera.mat3(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*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/datasets/msm_middlebury.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset description }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<MSM_middlebury> 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->getTrain().size());
|
||||
MSM_middleburyObj *example = static_cast<MSM_middleburyObj *>(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("\n");
|
||||
}
|
||||
printf("R:\n");
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
for (int j=0; j<3; ++j)
|
||||
{
|
||||
printf("%f ", example->r(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("t:\n");
|
||||
for (int i=0; i<3; ++i)
|
||||
{
|
||||
printf("%f ", example->t[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*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/datasets/or_imagenet.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to folder with dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<OR_imagenet> dataset = OR_imagenet::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains for each object its id & image path
|
||||
// For example, let output train\test\validation size and first image.
|
||||
vector< Ptr<Object> > &curr = dataset->getTrain();
|
||||
printf("train:\nsize: %u\n", (unsigned int)curr.size());
|
||||
OR_imagenetObj *example = static_cast<OR_imagenetObj *>(curr[0].get());
|
||||
printf("first image:\n");
|
||||
printf("image: %s\n", example->image.c_str());
|
||||
printf("id: %u\n", example->id);
|
||||
|
||||
vector< Ptr<Object> > &currT = dataset->getTest();
|
||||
printf("test:\nsize: %u\n", (unsigned int)currT.size());
|
||||
example = static_cast<OR_imagenetObj *>(currT[0].get());
|
||||
printf("first image:\n");
|
||||
printf("image: %s\n", example->image.c_str());
|
||||
printf("id: %u\n", example->id);
|
||||
|
||||
vector< Ptr<Object> > &currV = dataset->getValidation();
|
||||
printf("validation:\nsize: %u\n", (unsigned int)currV.size());
|
||||
example = static_cast<OR_imagenetObj *>(currV[0].get());
|
||||
printf("first image:\n");
|
||||
printf("image: %s\n", example->image.c_str());
|
||||
printf("id: %u\n", example->id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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/datasets/or_mnist.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<OR_mnist> dataset = OR_mnist::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains for each object its image and label.
|
||||
// For example, let output train & test sizes and their first elements.
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
OR_mnistObj *example = static_cast<OR_mnistObj *>(dataset->getTrain()[0].get());
|
||||
printf("first train:\nlabel: %u\n", example->label);
|
||||
printf("image was saved to train0.png\n");
|
||||
imwrite("train0.png", example->image);
|
||||
|
||||
example = static_cast<OR_mnistObj *>(dataset->getTest()[0].get());
|
||||
printf("first test:\nlabel: %u\n", example->label);
|
||||
printf("image was saved to test0.png\n");
|
||||
imwrite("test0.png", example->image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*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) 2015, 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/datasets/or_pascal.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to folder with dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<OR_pascal> dataset = OR_pascal::create();
|
||||
dataset->load(path);
|
||||
|
||||
// Print train/test/validation size and first example
|
||||
OR_pascalObj *example;
|
||||
vector< Ptr<Object> > &train = dataset->getTrain();
|
||||
printf("\ntrain:\nsize: %u", (unsigned int)train.size());
|
||||
example = static_cast<OR_pascalObj *>(train[0].get());
|
||||
printf("\nfirst image: \n%s", example->filename.c_str());
|
||||
|
||||
printf("\nsize:");
|
||||
printf("\n - width: %d", example->width);
|
||||
printf("\n - height: %d", example->height);
|
||||
printf("\n - depth: %d", example->depth);
|
||||
|
||||
for (unsigned int i = 0; i < example->objects.size(); i++)
|
||||
{
|
||||
printf("\nobject %d", i);
|
||||
printf("\nname: %s", example->objects[i].name.c_str());
|
||||
printf("\npose: %s", example->objects[i].pose.c_str());
|
||||
printf("\ntruncated: %d", example->objects[i].truncated);
|
||||
printf("\ndifficult: %d", example->objects[i].difficult);
|
||||
printf("\noccluded: %d", example->objects[i].occluded);
|
||||
|
||||
printf("\nbounding box:");
|
||||
printf("\n - xmin: %d", example->objects[i].xmin);
|
||||
printf("\n - ymin: %d", example->objects[i].ymin);
|
||||
printf("\n - xmax: %d", example->objects[i].xmax);
|
||||
printf("\n - ymax: %d", example->objects[i].ymax);
|
||||
}
|
||||
|
||||
vector< Ptr<Object> > &test = dataset->getTest();
|
||||
printf("\ntest:\nsize: %u", (unsigned int)test.size());
|
||||
example = static_cast<OR_pascalObj *>(test[0].get());
|
||||
printf("\nfirst image: \n%s", example->filename.c_str());
|
||||
|
||||
vector< Ptr<Object> > &validation = dataset->getValidation();
|
||||
printf("\nvalidation:\nsize: %u", (unsigned int)validation.size());
|
||||
example = static_cast<OR_pascalObj *>(validation[0].get());
|
||||
printf("\nfirst image: \n%s\n", example->filename.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*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/datasets/or_sun.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (SUN397 folder) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<OR_sun> dataset = OR_sun::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains for each object its images.
|
||||
// For example, let output splits number, dataset size and last image.
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
OR_sunObj *example = static_cast<OR_sunObj *>(dataset->getTrain().back().get());
|
||||
printf("last image:\nname: %s\n", example->name.c_str());
|
||||
printf("label: %u\n", example->label);
|
||||
printf("label path: %s\n", dataset->paths[example->label].c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*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/datasets/pd_caltech.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<PD_caltech> dataset = PD_caltech::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// dataset contains for each object its images.
|
||||
// currently on loading extract all images to folder path/../images/
|
||||
// For example, let output train size and first element of first object
|
||||
// and number of it's images.
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
PD_caltechObj *example = static_cast<PD_caltechObj *>(dataset->getTrain()[0].get());
|
||||
printf("first train object:\n");
|
||||
printf("name: %s\n", example->name.c_str());
|
||||
printf("images number: %u\n", (unsigned int)example->imageNames.size());
|
||||
printf("first image name: %s\n", example->imageNames[0].c_str());
|
||||
printf("images were extracted to path/../images/\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "opencv2/datasets/pd_inria.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true | path to dataset }"
|
||||
"{ save s |false| save resized positive images }"
|
||||
"{ rwidth rw |64 | width of resized positive images }"
|
||||
"{ rheight rh |128 | height of resized positive images }"
|
||||
"{ padding |8 | vertical padding of resized positive images }";
|
||||
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
bool savebbox = parser.get<bool>("save");
|
||||
int rwidth = parser.get<int>("rwidth");
|
||||
int rheight = parser.get<int>("rheight");
|
||||
int padding = parser.get<int>("padding");
|
||||
string path(parser.get<string>("path"));
|
||||
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<PD_inria> dataset = PD_inria::create();
|
||||
dataset->load(path);
|
||||
|
||||
size_t train_size = dataset->getTrain().size();
|
||||
size_t test_size = dataset->getTest().size();
|
||||
cout << "train size: " << train_size << endl;
|
||||
cout << "test size: " << test_size << endl;
|
||||
|
||||
int bbox_count = 0;
|
||||
|
||||
for( size_t i = 0; i < train_size; i++ )
|
||||
{
|
||||
PD_inriaObj *example = static_cast<PD_inriaObj *>(dataset->getTrain()[i].get());
|
||||
cout << "\ntrain object index: " << i << endl;
|
||||
cout << "file name: " << example->filename << endl;
|
||||
|
||||
// image size
|
||||
cout << "image size: " << endl;
|
||||
cout << " - width: " << example->width << endl;
|
||||
cout << " - height: " << example->height << endl;
|
||||
cout << " - depth: " << example->depth << endl;
|
||||
|
||||
Mat img = imread( example->filename );
|
||||
|
||||
// bounding boxes
|
||||
for ( size_t j = 0; j < example->bndboxes.size(); j++ )
|
||||
{
|
||||
Rect obj_bndbox = example->bndboxes[j]; // bounding box of object
|
||||
cout << " - bounding box: " << j << " - " << obj_bndbox << endl;
|
||||
|
||||
int vpadding, hpadding;
|
||||
Rect ex_bndbox; // variable used for calculating expanded bounding box
|
||||
|
||||
vpadding = cvRound(padding * obj_bndbox.height / rheight); // calculate vertical padding
|
||||
ex_bndbox.y = obj_bndbox.y - vpadding;
|
||||
ex_bndbox.height = 2 * vpadding + obj_bndbox.height;
|
||||
ex_bndbox.x = obj_bndbox.x + (obj_bndbox.width / 2);
|
||||
ex_bndbox.width = ex_bndbox.height * rwidth / rheight;
|
||||
ex_bndbox.x -= (ex_bndbox.width + 1) / 2;
|
||||
|
||||
if (obj_bndbox.width > ex_bndbox.width)
|
||||
{
|
||||
obj_bndbox.x += (obj_bndbox.width - ex_bndbox.width + 1) / 2;
|
||||
obj_bndbox.width = ex_bndbox.width;
|
||||
}
|
||||
|
||||
hpadding = obj_bndbox.x - ex_bndbox.x; // calculate horizontal padding
|
||||
|
||||
if(savebbox)
|
||||
{
|
||||
Mat dst;
|
||||
copyMakeBorder(img(obj_bndbox), dst, vpadding, vpadding, hpadding, hpadding, BORDER_REFLECT);
|
||||
resize(dst, dst, Size(rwidth, rheight), 0, 0, INTER_AREA);
|
||||
imwrite(path + format("person_%04d.png", bbox_count++), dst);
|
||||
}
|
||||
else
|
||||
rectangle(img, obj_bndbox, Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
if (savebbox)
|
||||
continue; // skip UI updates
|
||||
|
||||
imshow("INRIAPerson Dataset Train Images", img);
|
||||
cout << "\nPress a key to continue or ESC to exit." << endl;
|
||||
int key = waitKey();
|
||||
if( key == 27 ) break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*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/datasets/slam_kitti.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folders }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<SLAM_kitti> 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->getTrain().size());
|
||||
|
||||
SLAM_kittiObj *example = static_cast<SLAM_kittiObj *>(dataset->getTrain()[0].get());
|
||||
printf("first dataset sequence:\n%s\n", example->name.c_str());
|
||||
|
||||
/*string pathVelodyne(path + "sequences/" + example->name + "/velodyne/");
|
||||
for (vector<string>::iterator it=example->velodyne.begin(); it!=example->velodyne.end(); ++it)
|
||||
{
|
||||
printf("%s\n", (pathVelodyne + (*it)).c_str());
|
||||
}*/
|
||||
printf("number of velodyne images: %u\n", (unsigned int)example->velodyne.size());
|
||||
|
||||
for (unsigned int i=0; i<=3; ++i)
|
||||
{
|
||||
/*char tmp[2];
|
||||
sprintf(tmp, "%u", i);
|
||||
// 0,1 - gray, 2,3 - color
|
||||
string currPath(path + "sequences/" + example->name + "/image_" + tmp + "/");
|
||||
for (vector<string>::iterator it=example->images[i].begin(); it!=example->images[i].end(); ++it)
|
||||
{
|
||||
printf("%s\n", (currPath + (*it)).c_str());
|
||||
}*/
|
||||
printf("number of images %u: %u\n", i, (unsigned int)example->images[i].size());
|
||||
}
|
||||
|
||||
/*printf("times:\n");
|
||||
for (vector<double>::iterator it=example->times.begin(); it!=example->times.end(); ++it)
|
||||
{
|
||||
printf("%f ", *it);
|
||||
}
|
||||
printf("\n");*/
|
||||
printf("number of times: %u\n", (unsigned int)example->times.size());
|
||||
|
||||
/*printf("poses:\n");
|
||||
for (vector<pose>::iterator it=example->posesArray.begin(); it!=example->posesArray.end(); ++it)
|
||||
{
|
||||
for (unsigned int i=0; i<12; ++i)
|
||||
{
|
||||
printf("%f ", (*it).elem[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}*/
|
||||
printf("number of poses: %u\n", (unsigned int)example->posesArray.size());
|
||||
|
||||
for (unsigned int i=0; i<4; ++i)
|
||||
{
|
||||
printf("calibration %u:\n", i);
|
||||
for (vector<double>::iterator it=example->p[i].begin(); it!=example->p[i].end(); ++it)
|
||||
{
|
||||
printf("%f ", *it);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*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/datasets/slam_tumindoor.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset folders }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<SLAM_tumindoor> 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->getTrain().size());
|
||||
|
||||
SLAM_tumindoorObj *example = static_cast<SLAM_tumindoorObj *>(dataset->getTrain()[0].get());
|
||||
printf("first image:\ntype: %u\n", example->type);
|
||||
|
||||
string imagePath(path);
|
||||
if (LADYBUG == example->type)
|
||||
{
|
||||
imagePath += "ladybug/";
|
||||
} else
|
||||
{
|
||||
imagePath += "dslr/";
|
||||
}
|
||||
printf("file name: %s\n", (imagePath + example->name).c_str());
|
||||
|
||||
printf("\ntransformation matrix:\n");
|
||||
for (unsigned int i=0; i<4; ++i)
|
||||
{
|
||||
for (unsigned int j=0; j<4; ++j)
|
||||
{
|
||||
printf("%f ", example->transformMat(i, j));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/datasets/sr_bsds.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (images, iids_train.txt, iids_test.txt) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<SR_bsds> dataset = SR_bsds::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// Dataset train & test contain names of appropriate images.
|
||||
// For example, let's output full path & name for first train and test images.
|
||||
// And dataset sizes.
|
||||
printf("train size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
SR_bsdsObj *example1 = static_cast<SR_bsdsObj *>(dataset->getTrain()[0].get());
|
||||
string fullPath(path + "images/train/" + example1->imageName + ".jpg");
|
||||
printf("first train image: %s\n", fullPath.c_str());
|
||||
|
||||
SR_bsdsObj *example2 = static_cast<SR_bsdsObj *>(dataset->getTest()[0].get());
|
||||
fullPath = path + "images/test/" + example2->imageName + ".jpg";
|
||||
printf("first test image: %s\n", fullPath.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/datasets/sr_div2k.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (Div2k dataset folder containing the images) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<SR_div2k> dataset = SR_div2k::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// Dataset contains all images.
|
||||
// For example, let's output dataset size; first image name; and second image full path.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
SR_div2kObj *example = static_cast<SR_div2kObj *>(dataset->getTrain()[0].get());
|
||||
printf("first image name: %s\n", example->imageName.c_str());
|
||||
|
||||
SR_div2kObj *example2 = static_cast<SR_div2kObj *>(dataset->getTrain()[1].get());
|
||||
string fullPath = path + "/" + example2->imageName.c_str();
|
||||
printf("second image full path: %s\n", fullPath.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/datasets/sr_general100.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset (General-100 dataset folder) }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<SR_general100> dataset = SR_general100::create();
|
||||
dataset->load(path);
|
||||
|
||||
// ***************
|
||||
// Dataset contains all images.
|
||||
// For example, let's output dataset size; first image name; and second image full path.
|
||||
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
|
||||
|
||||
SR_general100Obj *example = static_cast<SR_general100Obj *>(dataset->getTrain()[0].get());
|
||||
printf("first image name: %s\n", example->imageName.c_str());
|
||||
|
||||
SR_general100Obj *example2 = static_cast<SR_general100Obj *>(dataset->getTrain()[1].get());
|
||||
string fullPath = path + "/" + example2->imageName.c_str();
|
||||
printf("second image full path: %s\n", fullPath.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*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/datasets/tr_chars.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset description file: list_English_Img.m }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<TR_chars> 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.
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
|
||||
vector< Ptr<Object> > &currTrain = dataset->getTrain(numSplits-1);
|
||||
vector< Ptr<Object> > &currTest = dataset->getTest(numSplits-1);
|
||||
vector< Ptr<Object> > &currValidation = dataset->getValidation(numSplits-1);
|
||||
printf("train size: %u\n", (unsigned int)currTrain.size());
|
||||
printf("test size: %u\n", (unsigned int)currTest.size());
|
||||
printf("validation size: %u\n", (unsigned int)currValidation.size());
|
||||
|
||||
TR_charsObj *exampleTrain = static_cast<TR_charsObj *>(currTrain[0].get());
|
||||
TR_charsObj *exampleTest = static_cast<TR_charsObj *>(currTest[0].get());
|
||||
TR_charsObj *exampleValidation = static_cast<TR_charsObj *>(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;
|
||||
}
|
||||
@@ -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 <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_TEXT
|
||||
|
||||
#include "opencv2/datasets/tr_chars.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include "opencv2/text.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
using namespace cv::text;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset description file ( list_English_Img.m ) and Img folder.}";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<TR_chars> 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.
|
||||
int numSplits = dataset->getNumSplits();
|
||||
printf("splits number: %u\n", numSplits);
|
||||
|
||||
vector< Ptr<Object> > &currTrain = dataset->getTrain(numSplits-1);
|
||||
vector< Ptr<Object> > &currTest = dataset->getTest(numSplits-1);
|
||||
vector< Ptr<Object> > &currValidation = dataset->getValidation(numSplits-1);
|
||||
printf("train size: %u\n", (unsigned int)currTrain.size());
|
||||
printf("test size: %u\n", (unsigned int)currTest.size());
|
||||
printf("validation size: %u\n", (unsigned int)currValidation.size());
|
||||
|
||||
|
||||
// WARNING: The order of classes' labels is different in Chars74k and in the output of our classifier
|
||||
string src_classes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // labels order as in the clasifier output
|
||||
string tar_classes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; // labels order as in the Chars74k dataset
|
||||
|
||||
Ptr<OCRHMMDecoder::ClassifierCallback> ocr = loadOCRHMMClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz");
|
||||
|
||||
int numOK = 0;
|
||||
int upperNumOK = 0;
|
||||
|
||||
for (unsigned int i=0; i<(unsigned int)currTest.size(); i++)
|
||||
{
|
||||
TR_charsObj *exampleTest = static_cast<TR_charsObj *>(currTest[i].get());
|
||||
printf("processed image: %u, name: %s\n", i, exampleTest->imgName.c_str());
|
||||
printf(" label: %u,", exampleTest->label);
|
||||
|
||||
string imfilename = path+string("/Img/")+exampleTest->imgName.c_str()+string(".png");
|
||||
Mat image = imread(imfilename);
|
||||
vector<int> out_classes;
|
||||
vector<double> out_confidences;
|
||||
ocr->eval(image, out_classes, out_confidences);
|
||||
int prediction = 1 + tar_classes.find_first_of(src_classes[out_classes[0]]);
|
||||
printf(" prediction: %u\n", prediction);
|
||||
|
||||
if (exampleTest->label == prediction)
|
||||
numOK++;
|
||||
|
||||
char l = tar_classes[exampleTest->label];
|
||||
char p = tar_classes[prediction];
|
||||
if (toupper(l) == toupper(p))
|
||||
upperNumOK++;
|
||||
}
|
||||
|
||||
printf("\n---------------------------------------------\n");
|
||||
printf("Chars74k Classification Accuracy (case-sensitive): %f\n",(float)numOK/currTest.size());
|
||||
printf("Chars74k Classification Accuracy (case-insensitive): %f\n",(float)upperNumOK/currTest.size());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without text module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_TEXT
|
||||
@@ -0,0 +1,101 @@
|
||||
/*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/datasets/tr_icdar.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset root folder }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading train & test images description
|
||||
Ptr<TR_icdar> dataset = TR_icdar::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->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
TR_icdarObj *example = static_cast<TR_icdarObj *>(dataset->getTrain().back().get());
|
||||
printf("last element:\nfile name: %s", example->fileName.c_str());
|
||||
printf("\nlex100: ");
|
||||
for (vector<string>::iterator it=example->lex100.begin(); it!=example->lex100.end(); ++it)
|
||||
{
|
||||
printf("%s,", (*it).c_str());
|
||||
}
|
||||
printf("\nlexFULL: ");
|
||||
for (vector<string>::iterator it=example->lexFull.begin(); it!=example->lexFull.end(); ++it)
|
||||
{
|
||||
printf("%s,", (*it).c_str());
|
||||
}
|
||||
printf("\nwords:\n");
|
||||
for (vector<word>::iterator it=example->words.begin(); it!=example->words.end(); ++it)
|
||||
{
|
||||
word &t = (*it);
|
||||
printf("%s\nheight: %u, width: %u, x: %u, y: %u\n",
|
||||
t.value.c_str(), t.height, t.width, t.x, t.y);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,522 @@
|
||||
/*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 <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_TEXT
|
||||
|
||||
#include "opencv2/datasets/tr_icdar.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include "opencv2/text.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
using namespace cv::text;
|
||||
|
||||
//Calculate edit distance between two words
|
||||
size_t edit_distance(const string& A, const string& B);
|
||||
size_t min(size_t x, size_t y, size_t z);
|
||||
bool isRepetitive(const string& s);
|
||||
bool sort_by_length(const string &a, const string &b);
|
||||
//Draw ER's in an image via floodFill
|
||||
void er_draw(vector<Mat> &channels, vector<vector<ERStat> > ®ions, vector<Vec2i> group, Mat& segmentation);
|
||||
|
||||
size_t min(size_t x, size_t y, size_t z)
|
||||
{
|
||||
return x < y ? min(x,z) : min(y,z);
|
||||
}
|
||||
|
||||
size_t edit_distance(const string& A, const string& B)
|
||||
{
|
||||
size_t NA = A.size();
|
||||
size_t NB = B.size();
|
||||
|
||||
vector< vector<size_t> > M(NA + 1, vector<size_t>(NB + 1));
|
||||
|
||||
for (size_t a = 0; a <= NA; ++a)
|
||||
M[a][0] = a;
|
||||
|
||||
for (size_t b = 0; b <= NB; ++b)
|
||||
M[0][b] = b;
|
||||
|
||||
for (size_t a = 1; a <= NA; ++a)
|
||||
for (size_t b = 1; b <= NB; ++b)
|
||||
{
|
||||
size_t x = M[a-1][b] + 1;
|
||||
size_t y = M[a][b-1] + 1;
|
||||
size_t z = M[a-1][b-1] + (A[a-1] == B[b-1] ? 0 : 1);
|
||||
M[a][b] = min(x,y,z);
|
||||
}
|
||||
|
||||
return M[A.size()][B.size()];
|
||||
}
|
||||
|
||||
bool sort_by_length(const string &a, const string &b){return (a.size()>b.size());}
|
||||
|
||||
bool isRepetitive(const string& s)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i=0; i<(int)s.size(); i++)
|
||||
{
|
||||
if ((s[i] == 'i') ||
|
||||
(s[i] == 'l') ||
|
||||
(s[i] == 'I'))
|
||||
count++;
|
||||
}
|
||||
if (count > ((int)s.size()+1)/2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void er_draw(vector<Mat> &channels, vector<vector<ERStat> > ®ions, vector<Vec2i> group, Mat& segmentation)
|
||||
{
|
||||
for (int r=0; r<(int)group.size(); r++)
|
||||
{
|
||||
ERStat er = regions[group[r][0]][group[r][1]];
|
||||
if (er.parent != NULL) // deprecate the root region
|
||||
{
|
||||
int newMaskVal = 255;
|
||||
int flags = 4 + (newMaskVal << 8) + FLOODFILL_FIXED_RANGE + FLOODFILL_MASK_ONLY;
|
||||
floodFill(channels[group[r][0]],segmentation,Point(er.pixel%channels[group[r][0]].cols,er.pixel/channels[group[r][0]].cols),
|
||||
Scalar(255),0,Scalar(er.level),Scalar(0),flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// std::toupper is int->int
|
||||
static char char_toupper(char ch)
|
||||
{
|
||||
return (char)std::toupper((int)ch);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset root folder }"
|
||||
"{ ws wordspotting| | evaluate \"word spotting\" results }"
|
||||
"{ lex lexicon |1 | 0:no-lexicon, 1:100-words, 2:full-lexicon }";
|
||||
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool is_word_spotting = parser.has("ws");
|
||||
int selected_lex = parser.get<int>("lex");
|
||||
if ((selected_lex < 0) || (selected_lex > 2))
|
||||
{
|
||||
parser.printMessage();
|
||||
printf("Unsupported lex value.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading train & test images description
|
||||
Ptr<TR_icdar> dataset = TR_icdar::create();
|
||||
dataset->load(path);
|
||||
|
||||
|
||||
vector<double> f1Each;
|
||||
|
||||
unsigned int correctNum = 0;
|
||||
unsigned int returnedNum = 0;
|
||||
unsigned int returnedCorrectNum = 0;
|
||||
|
||||
vector< Ptr<Object> >& test = dataset->getTest();
|
||||
unsigned int num = 0;
|
||||
for (vector< Ptr<Object> >::iterator itT=test.begin(); itT!=test.end(); ++itT)
|
||||
{
|
||||
TR_icdarObj *example = static_cast<TR_icdarObj *>((*itT).get());
|
||||
|
||||
num++;
|
||||
printf("processed image: %u, name: %s\n", num, example->fileName.c_str());
|
||||
|
||||
vector<string> empty_lexicon;
|
||||
vector<string> *lex;
|
||||
switch (selected_lex)
|
||||
{
|
||||
case 0:
|
||||
lex = &empty_lexicon;
|
||||
break;
|
||||
case 2:
|
||||
lex = &example->lexFull;
|
||||
break;
|
||||
default:
|
||||
lex = &example->lex100;
|
||||
break;
|
||||
}
|
||||
|
||||
correctNum += example->words.size();
|
||||
unsigned int correctNumEach = example->words.size();
|
||||
|
||||
// Take care of dontcare regions t.value == "###"
|
||||
for (size_t w=0; w<example->words.size(); w++)
|
||||
{
|
||||
string w_upper = example->words[w].value;
|
||||
transform(w_upper.begin(), w_upper.end(), w_upper.begin(), char_toupper);
|
||||
if ((find (lex->begin(), lex->end(), w_upper) == lex->end()) &&
|
||||
(is_word_spotting) && (selected_lex != 0))
|
||||
example->words[w].value = "###";
|
||||
if ( (example->words[w].value == "###") || (example->words[w].value.size()<3) )
|
||||
{
|
||||
correctNum --;
|
||||
correctNumEach --;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int returnedNumEach = 0;
|
||||
unsigned int returnedCorrectNumEach = 0;
|
||||
|
||||
Mat image = imread((path+"/test/"+example->fileName).c_str());
|
||||
|
||||
/*Text Detection*/
|
||||
|
||||
// Extract channels to be processed individually
|
||||
vector<Mat> channels;
|
||||
|
||||
Mat grey;
|
||||
cvtColor(image,grey,COLOR_RGB2GRAY);
|
||||
|
||||
// Notice here we are only using grey channel, see textdetection.cpp for example with more channels
|
||||
channels.push_back(grey);
|
||||
channels.push_back(255-grey);
|
||||
|
||||
|
||||
// Create ERFilter objects with the 1st and 2nd sworde default classifiers
|
||||
Ptr<ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("trained_classifierNM1.xml"),8,0.00015f,0.13f,0.2f,true,0.1f);
|
||||
Ptr<ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("trained_classifierNM2.xml"),0.5);
|
||||
|
||||
vector<vector<ERStat> > regions(channels.size());
|
||||
// Apply the default cascade classifier to each independent channel (could be done in parallel)
|
||||
for (int c=0; c<(int)channels.size(); c++)
|
||||
{
|
||||
er_filter1->run(channels[c], regions[c]);
|
||||
er_filter2->run(channels[c], regions[c]);
|
||||
}
|
||||
|
||||
// Detect character groups
|
||||
vector< vector<Vec2i> > nm_region_groups;
|
||||
vector<Rect> nm_boxes;
|
||||
erGrouping(image, channels, regions, nm_region_groups, nm_boxes, ERGROUPING_ORIENTATION_HORIZ);
|
||||
|
||||
/*Text Recognition (OCR)*/
|
||||
|
||||
Ptr<OCRTesseract> ocr = OCRTesseract::create();
|
||||
bool ocr_is_tesseract = true;
|
||||
|
||||
vector<string> final_words;
|
||||
vector<Rect> final_boxes;
|
||||
vector<float> final_confs;
|
||||
for (int i=0; i<(int)nm_boxes.size(); i++)
|
||||
{
|
||||
Mat group_img = Mat::zeros(image.rows+2, image.cols+2, CV_8UC1);
|
||||
er_draw(channels, regions, nm_region_groups[i], group_img);
|
||||
if (ocr_is_tesseract)
|
||||
{
|
||||
group_img(nm_boxes[i]).copyTo(group_img);
|
||||
copyMakeBorder(group_img,group_img,15,15,15,15,BORDER_CONSTANT,Scalar(0));
|
||||
} else {
|
||||
group_img(Rect(1,1,image.cols,image.rows)).copyTo(group_img);
|
||||
}
|
||||
|
||||
string output;
|
||||
vector<Rect> boxes;
|
||||
vector<string> words;
|
||||
vector<float> confidences;
|
||||
ocr->run(grey, group_img, output, &boxes, &words, &confidences, OCR_LEVEL_WORD);
|
||||
|
||||
output.erase(remove(output.begin(), output.end(), '\n'), output.end());
|
||||
//cout << "OCR output = \"" << output << "\" length = " << output.size() << endl;
|
||||
|
||||
if (output.size() < 3)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<(int)boxes.size(); j++)
|
||||
{
|
||||
if (ocr_is_tesseract)
|
||||
{
|
||||
boxes[j].x += nm_boxes[i].x-15;
|
||||
boxes[j].y += nm_boxes[i].y-15;
|
||||
}
|
||||
|
||||
float min_confidence = (ocr_is_tesseract)? (float)51. : (float)0.;
|
||||
float min_confidence4 = (ocr_is_tesseract)? (float)60. : (float)0.;
|
||||
//cout << " word = " << words[j] << "\t confidence = " << confidences[j] << endl;
|
||||
if ((words[j].size() < 2) || (confidences[j] < min_confidence) ||
|
||||
((words[j].size()==2) && (words[j][0] == words[j][1])) ||
|
||||
((words[j].size()< 4) && (confidences[j] < min_confidence4)) ||
|
||||
isRepetitive(words[j]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::transform(words[j].begin(), words[j].end(), words[j].begin(), char_toupper);
|
||||
|
||||
/* Increase confidence of predicted words matching a word in the lexicon */
|
||||
if (lex->size() > 0)
|
||||
{
|
||||
if (find(lex->begin(), lex->end(), words[j]) == lex->end())
|
||||
confidences[j] = 200;
|
||||
}
|
||||
|
||||
final_words.push_back(words[j]);
|
||||
final_boxes.push_back(boxes[j]);
|
||||
final_confs.push_back(confidences[j]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Non Maximal Suppression using OCR confidence */
|
||||
float thr = 0.5;
|
||||
|
||||
for (size_t i=0; i<final_words.size(); )
|
||||
{
|
||||
int to_delete = -1;
|
||||
for (size_t j=i+1; j<final_words.size(); )
|
||||
{
|
||||
to_delete = -1;
|
||||
Rect intersection = final_boxes[i] & final_boxes[j];
|
||||
float IoU = (float)intersection.area() / (final_boxes[i].area() + final_boxes[j].area() - intersection.area());
|
||||
if ((IoU > thr) || (intersection.area() > 0.8*final_boxes[i].area()) || (intersection.area() > 0.8*final_boxes[j].area()))
|
||||
{
|
||||
// if regions overlap more than thr delete the one with lower confidence
|
||||
to_delete = (final_confs[i] < final_confs[j]) ? i : j;
|
||||
|
||||
if (to_delete == (int)j )
|
||||
{
|
||||
final_words.erase(final_words.begin()+j);
|
||||
final_boxes.erase(final_boxes.begin()+j);
|
||||
final_confs.erase(final_confs.begin()+j);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (to_delete == (int)i )
|
||||
{
|
||||
final_words.erase(final_words.begin()+i);
|
||||
final_boxes.erase(final_boxes.begin()+i);
|
||||
final_confs.erase(final_confs.begin()+i);
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Predicted words which are not in the lexicon are filtered
|
||||
or changed to match one (when edit distance ratio < 0.34)*/
|
||||
float max_edit_distance_ratio = (float)0.34;
|
||||
for (size_t j=0; j<final_boxes.size(); j++)
|
||||
{
|
||||
|
||||
if (lex->size() > 0)
|
||||
{
|
||||
if (find(lex->begin(), lex->end(), final_words[j]) == lex->end())
|
||||
{
|
||||
int best_match = -1;
|
||||
int best_dist = final_words[j].size();
|
||||
for (size_t l=0; l<lex->size(); l++)
|
||||
{
|
||||
int dist = edit_distance(lex->at(l),final_words[j]);
|
||||
if (dist < best_dist)
|
||||
{
|
||||
best_match = l;
|
||||
best_dist = dist;
|
||||
}
|
||||
}
|
||||
if (best_dist/final_words[j].size() < max_edit_distance_ratio)
|
||||
final_words[j] = lex->at(best_match);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((find (lex->begin(), lex->end(), final_words[j])
|
||||
== lex->end()) && (is_word_spotting) && (selected_lex != 0))
|
||||
continue;
|
||||
|
||||
// Output final recognition in csv format compatible with the ICDAR Competition
|
||||
/*cout << final_boxes[j].tl().x << ","
|
||||
<< final_boxes[j].tl().y << ","
|
||||
<< min(final_boxes[j].br().x,image.cols-2)
|
||||
<< "," << final_boxes[j].tl().y << ","
|
||||
<< min(final_boxes[j].br().x,image.cols-2) << ","
|
||||
<< min(final_boxes[j].br().y,image.rows-2) << ","
|
||||
<< final_boxes[j].tl().x << ","
|
||||
<< min(final_boxes[j].br().y,image.rows-2) << ","
|
||||
<< final_words[j] << endl ;*/
|
||||
|
||||
returnedNum++;
|
||||
returnedNumEach++;
|
||||
|
||||
bool matched = false;
|
||||
for (vector<word>::iterator it=example->words.begin(); it!=example->words.end(); ++it)
|
||||
{
|
||||
word &t = (*it);
|
||||
|
||||
// ICDAR protocol accepts recognition up to the first non alphanumeric char
|
||||
string alnum_value = t.value;
|
||||
for (size_t c=0; c<alnum_value.size(); c++)
|
||||
{
|
||||
if (!isalnum(alnum_value[c]))
|
||||
{
|
||||
alnum_value = alnum_value.substr(0,c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::transform(t.value.begin(), t.value.end(), t.value.begin(), char_toupper);
|
||||
if (((t.value==final_words[j]) || (alnum_value==final_words[j])) &&
|
||||
!(final_boxes[j].tl().x > t.x+t.width || final_boxes[j].br().x < t.x ||
|
||||
final_boxes[j].tl().y > t.y+t.height || final_boxes[j].br().y < t.y))
|
||||
{
|
||||
matched = true;
|
||||
returnedCorrectNum++;
|
||||
returnedCorrectNumEach++;
|
||||
//cout << "OK!" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) // Take care of dontcare regions t.value == "###"
|
||||
for (vector<word>::iterator it=example->words.begin(); it!=example->words.end(); ++it)
|
||||
{
|
||||
word &t = (*it);
|
||||
std::transform(t.value.begin(), t.value.end(), t.value.begin(), char_toupper);
|
||||
if ((t.value == "###") &&
|
||||
!(final_boxes[j].tl().x > t.x+t.width || final_boxes[j].br().x < t.x ||
|
||||
final_boxes[j].tl().y > t.y+t.height || final_boxes[j].br().y < t.y))
|
||||
{
|
||||
matched = true;
|
||||
returnedNum--;
|
||||
returnedNumEach--;
|
||||
//cout << "DontCare!" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//if (!matched) cout << "FAIL." << endl;
|
||||
}
|
||||
|
||||
double p = 0.0;
|
||||
if (0 != returnedNumEach)
|
||||
{
|
||||
p = 1.0*returnedCorrectNumEach/returnedNumEach;
|
||||
}
|
||||
double r = 0.0;
|
||||
if (0 != correctNumEach)
|
||||
{
|
||||
r = 1.0*returnedCorrectNumEach/correctNumEach;
|
||||
}
|
||||
double f1 = 0.0;
|
||||
if (0 != p+r)
|
||||
{
|
||||
f1 = 2*(p*r)/(p+r);
|
||||
}
|
||||
if ( (correctNumEach == 0) && (returnedNumEach == 0) )
|
||||
{
|
||||
p = 1.;
|
||||
r = 1.;
|
||||
f1 = 1.;
|
||||
}
|
||||
//printf("|%f|%f|%f|\n",r,p,f1);
|
||||
f1Each.push_back(f1);
|
||||
}
|
||||
|
||||
double p = 1.0*returnedCorrectNum/returnedNum;
|
||||
double r = 1.0*returnedCorrectNum/correctNum;
|
||||
double f1 = 2*(p*r)/(p+r);
|
||||
|
||||
printf("\n-------------------------------------------------------------------------\n");
|
||||
printf("ICDAR2015 -- Challenge 2: \"Focused Scene Text\" -- Task 4 \"End-to-End\"\n");
|
||||
if (is_word_spotting) printf(" Word spotting results -- ");
|
||||
else printf(" End-to-End recognition results -- ");
|
||||
switch (selected_lex)
|
||||
{
|
||||
case 0:
|
||||
printf("generic recognition (no given lexicon)\n");
|
||||
break;
|
||||
case 2:
|
||||
printf("weakly contextualized lexicon (624 words)\n");
|
||||
break;
|
||||
default:
|
||||
printf("strongly contextualized lexicon (100 words)\n");
|
||||
break;
|
||||
}
|
||||
printf(" Recall: %f | Precision: %f | F-score: %f\n", r, p, f1);
|
||||
printf("-------------------------------------------------------------------------\n\n");
|
||||
|
||||
/*double mf1 = 0.0;
|
||||
for (vector<double>::iterator it=f1Each.begin(); it!=f1Each.end(); ++it)
|
||||
{
|
||||
mf1 += *it;
|
||||
}
|
||||
mf1 /= f1Each.size();
|
||||
printf("mean f1: %f\n", mf1);*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without text module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_TEXT
|
||||
@@ -0,0 +1,96 @@
|
||||
/*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/datasets/tr_svt.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset xml files }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading train & test images description
|
||||
Ptr<TR_svt> 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->getTrain().size());
|
||||
printf("test size: %u\n", (unsigned int)dataset->getTest().size());
|
||||
|
||||
TR_svtObj *example = static_cast<TR_svtObj *>(dataset->getTrain().back().get());
|
||||
printf("last element:\nfile name: %s", example->fileName.c_str());
|
||||
printf("\nlex: ");
|
||||
for (vector<string>::iterator it=example->lex.begin(); it!=example->lex.end(); ++it)
|
||||
{
|
||||
printf("%s,", (*it).c_str());
|
||||
}
|
||||
printf("\ntags:\n");
|
||||
for (vector<tag>::iterator it=example->tags.begin(); it!=example->tags.end(); ++it)
|
||||
{
|
||||
tag &t = (*it);
|
||||
printf("%s\nheight: %u, width: %u, x: %u, y: %u\n",
|
||||
t.value.c_str(), t.height, t.width, t.x, t.y);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
/*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 <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_TEXT
|
||||
|
||||
#include "opencv2/datasets/tr_svt.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include "opencv2/text.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // atoi
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
using namespace cv::text;
|
||||
|
||||
//Calculate edit distance between two words
|
||||
size_t edit_distance(const string& A, const string& B);
|
||||
size_t min(size_t x, size_t y, size_t z);
|
||||
bool isRepetitive(const string& s);
|
||||
bool sort_by_length(const string &a, const string &b);
|
||||
//Draw ER's in an image via floodFill
|
||||
void er_draw(vector<Mat> &channels, vector<vector<ERStat> > ®ions, vector<Vec2i> group, Mat& segmentation);
|
||||
|
||||
size_t min(size_t x, size_t y, size_t z)
|
||||
{
|
||||
return x < y ? min(x,z) : min(y,z);
|
||||
}
|
||||
|
||||
size_t edit_distance(const string& A, const string& B)
|
||||
{
|
||||
size_t NA = A.size();
|
||||
size_t NB = B.size();
|
||||
|
||||
vector< vector<size_t> > M(NA + 1, vector<size_t>(NB + 1));
|
||||
|
||||
for (size_t a = 0; a <= NA; ++a)
|
||||
M[a][0] = a;
|
||||
|
||||
for (size_t b = 0; b <= NB; ++b)
|
||||
M[0][b] = b;
|
||||
|
||||
for (size_t a = 1; a <= NA; ++a)
|
||||
for (size_t b = 1; b <= NB; ++b)
|
||||
{
|
||||
size_t x = M[a-1][b] + 1;
|
||||
size_t y = M[a][b-1] + 1;
|
||||
size_t z = M[a-1][b-1] + (A[a-1] == B[b-1] ? 0 : 1);
|
||||
M[a][b] = min(x,y,z);
|
||||
}
|
||||
|
||||
return M[A.size()][B.size()];
|
||||
}
|
||||
|
||||
bool sort_by_length(const string &a, const string &b){return (a.size()>b.size());}
|
||||
|
||||
bool isRepetitive(const string& s)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i=0; i<(int)s.size(); i++)
|
||||
{
|
||||
if ((s[i] == 'i') ||
|
||||
(s[i] == 'l') ||
|
||||
(s[i] == 'I'))
|
||||
count++;
|
||||
}
|
||||
if (count > ((int)s.size()+1)/2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void er_draw(vector<Mat> &channels, vector<vector<ERStat> > ®ions, vector<Vec2i> group, Mat& segmentation)
|
||||
{
|
||||
for (int r=0; r<(int)group.size(); r++)
|
||||
{
|
||||
ERStat er = regions[group[r][0]][group[r][1]];
|
||||
if (er.parent != NULL) // deprecate the root region
|
||||
{
|
||||
int newMaskVal = 255;
|
||||
int flags = 4 + (newMaskVal << 8) + FLOODFILL_FIXED_RANGE + FLOODFILL_MASK_ONLY;
|
||||
floodFill(channels[group[r][0]],segmentation,Point(er.pixel%channels[group[r][0]].cols,er.pixel/channels[group[r][0]].cols),
|
||||
Scalar(255),0,Scalar(er.level),Scalar(0),flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// std::toupper is int->int
|
||||
static char char_toupper(char ch)
|
||||
{
|
||||
return (char)std::toupper((int)ch);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to dataset xml files }";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
if (parser.has("help") || path=="true")
|
||||
{
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// loading train & test images description
|
||||
Ptr<TR_svt> dataset = TR_svt::create();
|
||||
dataset->load(path);
|
||||
|
||||
|
||||
vector<double> f1Each;
|
||||
|
||||
unsigned int correctNum = 0;
|
||||
unsigned int returnedNum = 0;
|
||||
unsigned int returnedCorrectNum = 0;
|
||||
|
||||
vector< Ptr<Object> >& test = dataset->getTest();
|
||||
unsigned int num = 0;
|
||||
for (vector< Ptr<Object> >::iterator itT=test.begin(); itT!=test.end(); ++itT)
|
||||
{
|
||||
TR_svtObj *example = static_cast<TR_svtObj *>((*itT).get());
|
||||
|
||||
num++;
|
||||
printf("processed image: %u, name: %s\n", num, example->fileName.c_str());
|
||||
|
||||
correctNum += example->tags.size();
|
||||
/* printf("\ntags:\n");
|
||||
for (vector<tag>::iterator it=example->tags.begin(); it!=example->tags.end(); ++it)
|
||||
{
|
||||
tag &t = (*it);
|
||||
printf("%s\nx: %u, y: %u, width: %u, height: %u\n",
|
||||
t.value.c_str(), t.x, t.y, t.x+t.width, t.y+t.height);
|
||||
}*/
|
||||
unsigned int correctNumEach = example->tags.size();
|
||||
unsigned int returnedNumEach = 0;
|
||||
unsigned int returnedCorrectNumEach = 0;
|
||||
|
||||
Mat image = imread((path+example->fileName).c_str());
|
||||
/*Text Detection*/
|
||||
|
||||
// Extract channels to be processed individually
|
||||
vector<Mat> channels;
|
||||
|
||||
Mat grey;
|
||||
cvtColor(image,grey,COLOR_RGB2GRAY);
|
||||
|
||||
// Notice here we are only using grey channel, see textdetection.cpp for example with more channels
|
||||
channels.push_back(grey);
|
||||
channels.push_back(255-grey);
|
||||
|
||||
// Create ERFilter objects with the 1st and 2nd stage default classifiers
|
||||
Ptr<ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("trained_classifierNM1.xml"),8,0.00015f,0.13f,0.2f,true,0.1f);
|
||||
Ptr<ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("trained_classifierNM2.xml"),0.5);
|
||||
|
||||
vector<vector<ERStat> > regions(channels.size());
|
||||
// Apply the default cascade classifier to each independent channel (could be done in parallel)
|
||||
for (int c=0; c<(int)channels.size(); c++)
|
||||
{
|
||||
er_filter1->run(channels[c], regions[c]);
|
||||
er_filter2->run(channels[c], regions[c]);
|
||||
}
|
||||
|
||||
// Detect character groups
|
||||
vector< vector<Vec2i> > nm_region_groups;
|
||||
vector<Rect> nm_boxes;
|
||||
erGrouping(image, channels, regions, nm_region_groups, nm_boxes, ERGROUPING_ORIENTATION_HORIZ);
|
||||
|
||||
|
||||
/*Text Recognition (OCR)*/
|
||||
|
||||
Ptr<OCRTesseract> ocr = OCRTesseract::create();
|
||||
for (int i=0; i<(int)nm_boxes.size(); i++)
|
||||
{
|
||||
Mat group_img = Mat::zeros(image.rows+2, image.cols+2, CV_8UC1);
|
||||
er_draw(channels, regions, nm_region_groups[i], group_img);
|
||||
group_img(nm_boxes[i]).copyTo(group_img);
|
||||
copyMakeBorder(group_img,group_img,15,15,15,15,BORDER_CONSTANT,Scalar(0));
|
||||
|
||||
string output;
|
||||
vector<Rect> boxes;
|
||||
vector<string> words;
|
||||
vector<float> confidences;
|
||||
ocr->run(group_img, output, &boxes, &words, &confidences, OCR_LEVEL_WORD);
|
||||
|
||||
output.erase(remove(output.begin(), output.end(), '\n'), output.end());
|
||||
//cout << "OCR output = \"" << output << "\" length = " << output.size() << endl;
|
||||
if (output.size() < 3)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<(int)boxes.size(); j++)
|
||||
{
|
||||
boxes[j].x += nm_boxes[i].x-15;
|
||||
boxes[j].y += nm_boxes[i].y-15;
|
||||
|
||||
//cout << " word = " << words[j] << "\t confidence = " << confidences[j] << endl;
|
||||
if ((words[j].size() < 2) || (confidences[j] < 51) ||
|
||||
((words[j].size()==2) && (words[j][0] == words[j][1])) ||
|
||||
((words[j].size()< 4) && (confidences[j] < 60)) ||
|
||||
isRepetitive(words[j]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::transform(words[j].begin(), words[j].end(), words[j].begin(), char_toupper);
|
||||
|
||||
if (find(example->lex.begin(), example->lex.end(), words[j]) == example->lex.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
returnedNum++;
|
||||
returnedNumEach++;
|
||||
/*printf("%s\nx: %u, y: %u, width: %u, height: %u\n",
|
||||
words[j].c_str(), boxes[j].tl().x, boxes[j].tl().y, boxes[j].br().x, boxes[j].br().y);*/
|
||||
for (vector<tag>::iterator it=example->tags.begin(); it!=example->tags.end(); ++it)
|
||||
{
|
||||
tag &t = (*it);
|
||||
if (t.value==words[j] &&
|
||||
!(boxes[j].tl().x > t.x+t.width || boxes[j].br().x < t.x ||
|
||||
boxes[j].tl().y > t.y+t.height || boxes[j].br().y < t.y))
|
||||
{
|
||||
returnedCorrectNum++;
|
||||
returnedCorrectNumEach++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
double p = 0.0;
|
||||
if (0 != returnedNumEach)
|
||||
{
|
||||
p = 1.0*returnedCorrectNumEach/returnedNumEach;
|
||||
}
|
||||
double r = 0.0;
|
||||
if (0 != correctNumEach)
|
||||
{
|
||||
r = 1.0*returnedCorrectNumEach/correctNumEach;
|
||||
}
|
||||
double f1 = 0.0;
|
||||
if (0 != p+r)
|
||||
{
|
||||
f1 = 2*(p*r)/(p+r);
|
||||
}
|
||||
//printf("|%f|\n", f1);
|
||||
f1Each.push_back(f1);
|
||||
}
|
||||
|
||||
double p = 1.0*returnedCorrectNum/returnedNum;
|
||||
double r = 1.0*returnedCorrectNum/correctNum;
|
||||
double f1 = 2*(p*r)/(p+r);
|
||||
printf("f1: %f\n", f1);
|
||||
|
||||
/*double f1 = 0.0;
|
||||
for (vector<double>::iterator it=f1Each.begin(); it!=f1Each.end(); ++it)
|
||||
{
|
||||
f1 += *it;
|
||||
}
|
||||
f1 /= f1Each.size();
|
||||
printf("mean f1: %f\n", f1);*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without text module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_TEXT
|
||||
@@ -0,0 +1,99 @@
|
||||
/*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/datasets/track_vot.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::datasets;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *keys =
|
||||
"{ help h usage ? | | show this message }"
|
||||
"{ path p |true| path to folder with dataset }"
|
||||
"{ datasetID id |1| Dataset ID}";
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
string path(parser.get<string>("path"));
|
||||
int datasetID(parser.get<int>("datasetID"));
|
||||
if (parser.has("help") || path == "true")
|
||||
{
|
||||
parser.printMessage();
|
||||
getchar();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Ptr<TRACK_vot> dataset = TRACK_vot::create();
|
||||
dataset->load(path);
|
||||
printf("Datasets number: %d\n", dataset->getDatasetsNum());
|
||||
for (int i = 1; i <= dataset->getDatasetsNum(); i++)
|
||||
printf("\tDataset #%d size: %d\n", i, dataset->getDatasetLength(i));
|
||||
|
||||
dataset->initDataset(datasetID);
|
||||
|
||||
for (int i = 0; i < dataset->getDatasetLength(datasetID); i++)
|
||||
{
|
||||
Mat frame;
|
||||
if (!dataset->getNextFrame(frame))
|
||||
break;
|
||||
//Draw Ground Truth BB
|
||||
vector <Point2d> gtPoints = dataset->getGT();
|
||||
for (int j = 0; j < (int)(gtPoints.size()-1); j++)
|
||||
line(frame, gtPoints[j], gtPoints[j + 1], Scalar(0, 255, 0), 2);
|
||||
line(frame, gtPoints[0], gtPoints[(int)(gtPoints.size()-1)], Scalar(0, 255, 0), 2);
|
||||
|
||||
imshow("VOT 2015 DATASET TEST...", frame);
|
||||
waitKey(100);
|
||||
}
|
||||
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user