parent
94447d5160
commit
cd5b061c67
3 changed files with 433 additions and 0 deletions
@ -0,0 +1,102 @@ |
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Itseez Inc or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_DATASETS_TRACK_VOT_HPP |
||||||
|
#define OPENCV_DATASETS_TRACK_VOT_HPP |
||||||
|
|
||||||
|
#include <string> |
||||||
|
#include <vector> |
||||||
|
#include <map> |
||||||
|
#include <iostream> |
||||||
|
|
||||||
|
#include "opencv2/datasets/dataset.hpp" |
||||||
|
#include "opencv2/datasets/util.hpp" |
||||||
|
#include <opencv2/highgui.hpp> |
||||||
|
|
||||||
|
#include <opencv2/core.hpp> |
||||||
|
#include <sys/stat.h> |
||||||
|
|
||||||
|
using namespace std; |
||||||
|
|
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
namespace datasets |
||||||
|
{ |
||||||
|
|
||||||
|
//! @addtogroup datasets_track
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
struct TRACK_votObj : public Object |
||||||
|
{ |
||||||
|
int id; |
||||||
|
std::string imagePath; |
||||||
|
vector <Point2d> gtbb; |
||||||
|
}; |
||||||
|
|
||||||
|
class CV_EXPORTS TRACK_vot : public Dataset |
||||||
|
{ |
||||||
|
public: |
||||||
|
static Ptr<TRACK_vot> create(); |
||||||
|
|
||||||
|
virtual void load(const std::string &path) = 0; |
||||||
|
|
||||||
|
virtual int getDatasetsNum() = 0; |
||||||
|
|
||||||
|
virtual int getDatasetLength(int id) = 0; |
||||||
|
|
||||||
|
virtual bool initDataset(int id) = 0; |
||||||
|
|
||||||
|
virtual bool getNextFrame(Mat &frame) = 0; |
||||||
|
|
||||||
|
virtual vector <Point2d> getGT() = 0; |
||||||
|
|
||||||
|
protected: |
||||||
|
vector <vector <Ptr<TRACK_votObj> > > data; |
||||||
|
int activeDatasetID; |
||||||
|
int frameCounter; |
||||||
|
}; |
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
@ -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/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; |
||||||
|
|
||||||
|
#define DATASET_ID 1 |
||||||
|
|
||||||
|
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(); |
||||||
|
getchar(); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
Ptr<TRACK_vot> dataset = TRACK_vot::create(); |
||||||
|
dataset->load("D:/opencv/VOT 2015"); |
||||||
|
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(DATASET_ID); |
||||||
|
|
||||||
|
for (int i = 0; i < dataset->getDatasetLength(DATASET_ID); i++) |
||||||
|
{ |
||||||
|
Mat frame; |
||||||
|
dataset->getNextFrame(frame); |
||||||
|
|
||||||
|
//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; |
||||||
|
} |
@ -0,0 +1,231 @@ |
|||||||
|
/*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" |
||||||
|
|
||||||
|
using namespace std; |
||||||
|
|
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
namespace datasets |
||||||
|
{ |
||||||
|
|
||||||
|
class TRACK_votImpl : public TRACK_vot |
||||||
|
{ |
||||||
|
public: |
||||||
|
//Constructor
|
||||||
|
TRACK_votImpl() |
||||||
|
{ |
||||||
|
|
||||||
|
activeDatasetID = 1; |
||||||
|
frameCounter = 0; |
||||||
|
} |
||||||
|
//Destructor
|
||||||
|
virtual ~TRACK_votImpl() {} |
||||||
|
|
||||||
|
//Load Dataset
|
||||||
|
virtual void load(const string &path); |
||||||
|
|
||||||
|
virtual int getDatasetsNum(); |
||||||
|
|
||||||
|
virtual int getDatasetLength(int id); |
||||||
|
|
||||||
|
virtual bool initDataset(int id); |
||||||
|
|
||||||
|
virtual bool getNextFrame(Mat &frame); |
||||||
|
|
||||||
|
virtual vector <Point2d> getGT(); |
||||||
|
|
||||||
|
private: |
||||||
|
void loadDataset(const string &path); |
||||||
|
|
||||||
|
string numberToString(int number); |
||||||
|
}; |
||||||
|
|
||||||
|
void TRACK_votImpl::load(const string &path) |
||||||
|
{ |
||||||
|
loadDataset(path); |
||||||
|
} |
||||||
|
|
||||||
|
string TRACK_votImpl::numberToString(int number) |
||||||
|
{ |
||||||
|
string out; |
||||||
|
char numberStr[9]; |
||||||
|
sprintf(numberStr, "%u", number); |
||||||
|
for (unsigned int i=0; i<8-strlen(numberStr); ++i) |
||||||
|
{ |
||||||
|
out += "0"; |
||||||
|
} |
||||||
|
out += numberStr; |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
inline bool fileExists(const std::string& name) |
||||||
|
{ |
||||||
|
struct stat buffer; |
||||||
|
return (stat(name.c_str(), &buffer) == 0); |
||||||
|
} |
||||||
|
|
||||||
|
void TRACK_votImpl::loadDataset(const string &rootPath) |
||||||
|
{ |
||||||
|
ifstream namesList(rootPath + "/list.txt"); |
||||||
|
//ifstream lengthsList(rootPath + "/lengths.txt");
|
||||||
|
vector <int> datasetsLengths; |
||||||
|
string datasetName; |
||||||
|
|
||||||
|
if (namesList.is_open()) |
||||||
|
{ |
||||||
|
int currDatasetID = 0; |
||||||
|
|
||||||
|
//All datasets/folders loop
|
||||||
|
while (getline(namesList, datasetName)) |
||||||
|
{ |
||||||
|
currDatasetID++; |
||||||
|
vector <Ptr<TRACK_votObj> > objects; |
||||||
|
|
||||||
|
//All frames/images loop
|
||||||
|
Ptr<TRACK_votObj> currDataset(new TRACK_votObj); |
||||||
|
|
||||||
|
//Open dataset's ground truth file
|
||||||
|
ifstream gtList(rootPath + "/" + datasetName + "/groundtruth.txt"); |
||||||
|
if (!gtList.is_open()) |
||||||
|
cout << "Error to open groundtruth.txt!!!"; |
||||||
|
|
||||||
|
//Make a list of datasets lengths
|
||||||
|
int currFrameID = 1; |
||||||
|
if (currDatasetID == 0) |
||||||
|
cout << "VOT 2015 Dataset Initialization...\n"; |
||||||
|
|
||||||
|
do |
||||||
|
{ |
||||||
|
currFrameID++; |
||||||
|
string fullPath = rootPath + "/" + datasetName + "/" + numberToString(currFrameID) + ".jpg"; |
||||||
|
if (!fileExists(fullPath)) |
||||||
|
break; |
||||||
|
|
||||||
|
//Make VOT Object
|
||||||
|
Ptr<TRACK_votObj> currObj(new TRACK_votObj); |
||||||
|
currObj->imagePath = fullPath; |
||||||
|
currObj->id = currFrameID; |
||||||
|
|
||||||
|
//Get Ground Truth data
|
||||||
|
double x1 = 0, y1 = 0, |
||||||
|
x2 = 0, y2 = 0, |
||||||
|
x3 = 0, y3 = 0, |
||||||
|
x4 = 0, y4 = 0; |
||||||
|
string tmp; |
||||||
|
getline(gtList, tmp); |
||||||
|
sscanf(tmp.c_str(), "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); |
||||||
|
currObj->gtbb.push_back(Point2d(x1, y1)); |
||||||
|
currObj->gtbb.push_back(Point2d(x2, y2)); |
||||||
|
currObj->gtbb.push_back(Point2d(x3, y3)); |
||||||
|
currObj->gtbb.push_back(Point2d(x4, y4)); |
||||||
|
|
||||||
|
//Add object to storage
|
||||||
|
objects.push_back(currObj); |
||||||
|
|
||||||
|
} while (true); |
||||||
|
|
||||||
|
datasetsLengths.push_back(currFrameID-1); |
||||||
|
data.push_back(objects); |
||||||
|
} |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
cout << rootPath + "Couldn't find a *list.txt* in VOT 2015 folder!!!"; |
||||||
|
} |
||||||
|
|
||||||
|
namesList.close(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
int TRACK_votImpl::getDatasetsNum() |
||||||
|
{ |
||||||
|
return data.size(); |
||||||
|
} |
||||||
|
|
||||||
|
int TRACK_votImpl::getDatasetLength(int id) |
||||||
|
{ |
||||||
|
if (id > 0 && id <= (int)data.size()) |
||||||
|
return data[id - 1].size(); |
||||||
|
else |
||||||
|
{ |
||||||
|
cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl; |
||||||
|
return -1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool TRACK_votImpl::initDataset(int id) |
||||||
|
{ |
||||||
|
if (id > 0 && id <= (int)data.size()) |
||||||
|
{ |
||||||
|
activeDatasetID = id; |
||||||
|
return true; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl; |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool TRACK_votImpl::getNextFrame(Mat &frame) |
||||||
|
{ |
||||||
|
frame = imread(data[activeDatasetID - 1][frameCounter]->imagePath); |
||||||
|
frameCounter++; |
||||||
|
return !frame.empty(); |
||||||
|
} |
||||||
|
|
||||||
|
Ptr<TRACK_vot> TRACK_vot::create() |
||||||
|
{ |
||||||
|
return Ptr<TRACK_votImpl>(new TRACK_votImpl); |
||||||
|
} |
||||||
|
|
||||||
|
vector <Point2d> TRACK_votImpl::getGT() |
||||||
|
{ |
||||||
|
Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1][frameCounter - 1]; |
||||||
|
return currObj->gtbb; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
Loading…
Reference in new issue