mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 19:44:14 +08:00
Added VOT2015 Dataset interface + VOT2015 sample cpp
This commit is contained in:
@@ -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,14 +41,11 @@
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
@@ -58,6 +55,7 @@ namespace cv
|
||||
//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,6 +75,7 @@ namespace cv
|
||||
|
||||
virtual vector <Point2d> getGT();
|
||||
|
||||
private:
|
||||
void loadDataset(const string &path);
|
||||
|
||||
string numberToString(int number);
|
||||
@@ -109,8 +107,8 @@ namespace cv
|
||||
|
||||
void TRACK_votImpl::loadDataset(const string &rootPath)
|
||||
{
|
||||
string nameListPath = rootPath + "/list.txt";
|
||||
ifstream namesList(nameListPath.c_str());
|
||||
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,7 +163,7 @@ namespace cv
|
||||
//Add object to storage
|
||||
objects.push_back(currObj);
|
||||
|
||||
} while (trFLG);
|
||||
} while (true);
|
||||
|
||||
datasetsLengths.push_back(currFrameID-1);
|
||||
data.push_back(objects);
|
||||
@@ -174,7 +171,7 @@ namespace cv
|
||||
}
|
||||
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();
|
||||
@@ -183,16 +180,16 @@ namespace cv
|
||||
|
||||
int TRACK_votImpl::getDatasetsNum()
|
||||
{
|
||||
return (int)(data.size());
|
||||
return data.size();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -206,17 +203,14 @@ 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);
|
||||
frame = imread(data[activeDatasetID - 1][frameCounter]->imagePath);
|
||||
frameCounter++;
|
||||
return !frame.empty();
|
||||
}
|
||||
@@ -234,3 +228,4 @@ namespace cv
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user