Added VOT2015 Dataset interface + VOT2015 sample cpp

pull/341/head
Vladimir 10 years ago
parent 44e790b8d6
commit 071092d97c
  1. 6
      modules/datasets/include/opencv2/datasets/track_vot.hpp
  2. 12
      modules/datasets/samples/track_vot.cpp
  3. 117
      modules/datasets/src/track_vot.cpp

@ -44,9 +44,15 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <iostream>
#include "opencv2/datasets/dataset.hpp" #include "opencv2/datasets/dataset.hpp"
#include "opencv2/datasets/util.hpp" #include "opencv2/datasets/util.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <sys/stat.h>
using namespace std; using namespace std;

@ -55,6 +55,8 @@ using namespace std;
using namespace cv; using namespace cv;
using namespace cv::datasets; using namespace cv::datasets;
#define DATASET_ID 1
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *keys = const char *keys =
@ -72,18 +74,18 @@ int main(int argc, char *argv[])
} }
Ptr<TRACK_vot> dataset = TRACK_vot::create(); Ptr<TRACK_vot> dataset = TRACK_vot::create();
dataset->load(path); dataset->load("D:/opencv/VOT 2015");
printf("Datasets number: %d\n", dataset->getDatasetsNum()); printf("Datasets number: %d\n", dataset->getDatasetsNum());
for (int i = 1; i <= dataset->getDatasetsNum(); i++) for (int i = 1; i <= dataset->getDatasetsNum(); i++)
printf("\tDataset #%d size: %d\n", i, dataset->getDatasetLength(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; Mat frame;
if (!dataset->getNextFrame(frame)) dataset->getNextFrame(frame);
break;
//Draw Ground Truth BB //Draw Ground Truth BB
vector <Point2d> gtPoints = dataset->getGT(); vector <Point2d> gtPoints = dataset->getGT();
for (int j = 0; j < (int)(gtPoints.size()-1); j++) for (int j = 0; j < (int)(gtPoints.size()-1); j++)

@ -41,23 +41,21 @@
#include "opencv2/datasets/track_vot.hpp" #include "opencv2/datasets/track_vot.hpp"
#include <sys/stat.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace std; using namespace std;
namespace cv namespace cv
{ {
namespace datasets
{
class TRACK_votImpl : public TRACK_vot namespace datasets
{ {
public:
class TRACK_votImpl : public TRACK_vot
{
public:
//Constructor //Constructor
TRACK_votImpl() TRACK_votImpl()
{ {
activeDatasetID = 1; activeDatasetID = 1;
frameCounter = 0; frameCounter = 0;
} }
@ -67,7 +65,6 @@ namespace cv
//Load Dataset //Load Dataset
virtual void load(const string &path); virtual void load(const string &path);
protected:
virtual int getDatasetsNum(); virtual int getDatasetsNum();
virtual int getDatasetLength(int id); virtual int getDatasetLength(int id);
@ -78,39 +75,40 @@ namespace cv
virtual vector <Point2d> getGT(); virtual vector <Point2d> getGT();
private:
void loadDataset(const string &path); void loadDataset(const string &path);
string numberToString(int number); string numberToString(int number);
}; };
void TRACK_votImpl::load(const string &path) void TRACK_votImpl::load(const string &path)
{ {
loadDataset(path); loadDataset(path);
} }
string TRACK_votImpl::numberToString(int number) string TRACK_votImpl::numberToString(int number)
{ {
string out; string out;
char numberStr[9]; char numberStr[9];
sprintf(numberStr, "%u", number); 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 += "0";
} }
out += numberStr; out += numberStr;
return out; return out;
} }
inline bool fileExists(const std::string& name) inline bool fileExists(const std::string& name)
{ {
struct stat buffer; struct stat buffer;
return (stat(name.c_str(), &buffer) == 0); return (stat(name.c_str(), &buffer) == 0);
} }
void TRACK_votImpl::loadDataset(const string &rootPath) void TRACK_votImpl::loadDataset(const string &rootPath)
{ {
string nameListPath = rootPath + "/list.txt"; ifstream namesList(rootPath + "/list.txt");
ifstream namesList(nameListPath.c_str()); //ifstream lengthsList(rootPath + "/lengths.txt");
vector <int> datasetsLengths; vector <int> datasetsLengths;
string datasetName; string datasetName;
@ -128,16 +126,15 @@ namespace cv
Ptr<TRACK_votObj> currDataset(new TRACK_votObj); Ptr<TRACK_votObj> currDataset(new TRACK_votObj);
//Open dataset's ground truth file //Open dataset's ground truth file
string gtListPath = rootPath + "/" + datasetName + "/groundtruth.txt"; ifstream gtList(rootPath + "/" + datasetName + "/groundtruth.txt");
ifstream gtList(gtListPath.c_str());
if (!gtList.is_open()) if (!gtList.is_open())
printf("Error to open groundtruth.txt!!!"); cout << "Error to open groundtruth.txt!!!";
//Make a list of datasets lengths //Make a list of datasets lengths
int currFrameID = 1; int currFrameID = 1;
if (currDatasetID == 0) if (currDatasetID == 0)
printf("VOT 2015 Dataset Initialization...\n"); cout << "VOT 2015 Dataset Initialization...\n";
bool trFLG = true;
do do
{ {
currFrameID++; currFrameID++;
@ -166,39 +163,39 @@ namespace cv
//Add object to storage //Add object to storage
objects.push_back(currObj); objects.push_back(currObj);
} while (trFLG); } while (true);
datasetsLengths.push_back(currFrameID - 1); datasetsLengths.push_back(currFrameID-1);
data.push_back(objects); data.push_back(objects);
} }
} }
else 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(); namesList.close();
return; return;
} }
int TRACK_votImpl::getDatasetsNum() int TRACK_votImpl::getDatasetsNum()
{ {
return (int)(data.size()); return data.size();
} }
int TRACK_votImpl::getDatasetLength(int id) int TRACK_votImpl::getDatasetLength(int id)
{ {
if (id > 0 && id <= (int)data.size()) if (id > 0 && id <= (int)data.size())
return (int)(data[id - 1].size()); return data[id - 1].size();
else 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; return -1;
} }
} }
bool TRACK_votImpl::initDataset(int id) bool TRACK_votImpl::initDataset(int id)
{ {
if (id > 0 && id <= (int)data.size()) if (id > 0 && id <= (int)data.size())
{ {
activeDatasetID = id; activeDatasetID = id;
@ -206,31 +203,29 @@ namespace cv
} }
else 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; return false;
} }
} }
bool TRACK_votImpl::getNextFrame(Mat &frame) bool TRACK_votImpl::getNextFrame(Mat &frame)
{ {
if (frameCounter >= (int)data[activeDatasetID - 1].size()) frame = imread(data[activeDatasetID - 1][frameCounter]->imagePath);
return false;
string imgPath = data[activeDatasetID - 1][frameCounter]->imagePath;
frame = imread(imgPath);
frameCounter++; frameCounter++;
return !frame.empty(); return !frame.empty();
} }
Ptr<TRACK_vot> TRACK_vot::create() Ptr<TRACK_vot> TRACK_vot::create()
{ {
return Ptr<TRACK_votImpl>(new TRACK_votImpl); 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]; Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1][frameCounter - 1];
return currObj->gtbb; return currObj->gtbb;
} }
}
} }
}

Loading…
Cancel
Save