1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-20 12:55:15 +08:00

Added VOT2015 Dataset interface + VOT2015 sample cpp

This commit is contained in:
Vladimir
2015-08-21 04:06:58 +09:00
parent 44e790b8d6
commit 071092d97c
3 changed files with 205 additions and 202 deletions

View File

@@ -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;

View File

@@ -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++)

View File

@@ -41,14 +41,11 @@
#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 namespace datasets
{ {
@@ -58,6 +55,7 @@ namespace cv
//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,6 +75,7 @@ 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);
@@ -109,8 +107,8 @@ namespace cv
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,7 +163,7 @@ 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);
@@ -174,7 +171,7 @@ namespace cv
} }
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();
@@ -183,16 +180,16 @@ namespace cv
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;
} }
} }
@@ -206,17 +203,14 @@ 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();
} }
@@ -234,3 +228,4 @@ namespace cv
} }
} }