Commit 071092d9 authored by Vladimir's avatar Vladimir

Added VOT2015 Dataset interface + VOT2015 sample cpp

parent 44e790b8
......@@ -44,9 +44,15 @@
#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;
......
......@@ -55,6 +55,8 @@ using namespace std;
using namespace cv;
using namespace cv::datasets;
#define DATASET_ID 1
int main(int argc, char *argv[])
{
const char *keys =
......@@ -72,18 +74,18 @@ int main(int argc, char *argv[])
}
Ptr<TRACK_vot> dataset = TRACK_vot::create();
dataset->load(path);
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(datasetID);
dataset->initDataset(DATASET_ID);
for (int i = 0; i < dataset->getDatasetLength(datasetID); i++)
for (int i = 0; i < dataset->getDatasetLength(DATASET_ID); i++)
{
Mat frame;
if (!dataset->getNextFrame(frame))
break;
dataset->getNextFrame(frame);
//Draw Ground Truth BB
vector <Point2d> gtPoints = dataset->getGT();
for (int j = 0; j < (int)(gtPoints.size()-1); j++)
......
......@@ -41,23 +41,21 @@
#include "opencv2/datasets/track_vot.hpp"
#include <sys/stat.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
namespace cv
{
namespace datasets
{
class TRACK_votImpl : public TRACK_vot
{
public:
namespace datasets
{
class TRACK_votImpl : public TRACK_vot
{
public:
//Constructor
TRACK_votImpl()
{
activeDatasetID = 1;
frameCounter = 0;
}
......@@ -67,7 +65,6 @@ namespace cv
//Load Dataset
virtual void load(const string &path);
protected:
virtual int getDatasetsNum();
virtual int getDatasetLength(int id);
......@@ -78,39 +75,40 @@ namespace cv
virtual vector <Point2d> getGT();
private:
void loadDataset(const string &path);
string numberToString(int number);
};
};
void TRACK_votImpl::load(const string &path)
{
void TRACK_votImpl::load(const string &path)
{
loadDataset(path);
}
}
string TRACK_votImpl::numberToString(int number)
{
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)
for (unsigned int i=0; i<8-strlen(numberStr); ++i)
{
out += "0";
}
out += numberStr;
return out;
}
}
inline bool fileExists(const std::string& name)
{
inline bool fileExists(const std::string& name)
{
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}
}
void TRACK_votImpl::loadDataset(const string &rootPath)
{
string nameListPath = rootPath + "/list.txt";
ifstream namesList(nameListPath.c_str());
void TRACK_votImpl::loadDataset(const string &rootPath)
{
ifstream namesList(rootPath + "/list.txt");
//ifstream lengthsList(rootPath + "/lengths.txt");
vector <int> datasetsLengths;
string datasetName;
......@@ -128,16 +126,15 @@ namespace cv
Ptr<TRACK_votObj> currDataset(new TRACK_votObj);
//Open dataset's ground truth file
string gtListPath = rootPath + "/" + datasetName + "/groundtruth.txt";
ifstream gtList(gtListPath.c_str());
ifstream gtList(rootPath + "/" + datasetName + "/groundtruth.txt");
if (!gtList.is_open())
printf("Error to open groundtruth.txt!!!");
cout << "Error to open groundtruth.txt!!!";
//Make a list of datasets lengths
int currFrameID = 1;
if (currDatasetID == 0)
printf("VOT 2015 Dataset Initialization...\n");
bool trFLG = true;
cout << "VOT 2015 Dataset Initialization...\n";
do
{
currFrameID++;
......@@ -166,39 +163,39 @@ namespace cv
//Add object to storage
objects.push_back(currObj);
} while (trFLG);
} while (true);
datasetsLengths.push_back(currFrameID - 1);
datasetsLengths.push_back(currFrameID-1);
data.push_back(objects);
}
}
else
{
printf("Couldn't find a *list.txt* in VOT 2015 folder!!!");
cout << rootPath + "Couldn't find a *list.txt* in VOT 2015 folder!!!";
}
namesList.close();
return;
}
}
int TRACK_votImpl::getDatasetsNum()
{
return (int)(data.size());
}
int TRACK_votImpl::getDatasetsNum()
{
return data.size();
}
int TRACK_votImpl::getDatasetLength(int id)
{
int TRACK_votImpl::getDatasetLength(int id)
{
if (id > 0 && id <= (int)data.size())
return (int)(data[id - 1].size());
return data[id - 1].size();
else
{
printf("Dataset ID is out of range...\nAllowed IDs are: 1~%d\n", (int)data.size());
cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl;
return -1;
}
}
}
bool TRACK_votImpl::initDataset(int id)
{
bool TRACK_votImpl::initDataset(int id)
{
if (id > 0 && id <= (int)data.size())
{
activeDatasetID = id;
......@@ -206,31 +203,29 @@ namespace cv
}
else
{
printf("Dataset ID is out of range...\nAllowed IDs are: 1~%d\n", (int)data.size());
cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl;
return false;
}
}
}
bool TRACK_votImpl::getNextFrame(Mat &frame)
{
if (frameCounter >= (int)data[activeDatasetID - 1].size())
return false;
string imgPath = data[activeDatasetID - 1][frameCounter]->imagePath;
frame = imread(imgPath);
bool TRACK_votImpl::getNextFrame(Mat &frame)
{
frame = imread(data[activeDatasetID - 1][frameCounter]->imagePath);
frameCounter++;
return !frame.empty();
}
}
Ptr<TRACK_vot> TRACK_vot::create()
{
Ptr<TRACK_vot> TRACK_vot::create()
{
return Ptr<TRACK_votImpl>(new TRACK_votImpl);
}
}
vector <Point2d> TRACK_votImpl::getGT()
{
vector <Point2d> TRACK_votImpl::getGT()
{
Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1][frameCounter - 1];
return currObj->gtbb;
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment