Commit 78a968cc authored by Vladimir's avatar Vladimir

Fix #1

parent f5ce6d76
...@@ -45,186 +45,185 @@ using namespace std; ...@@ -45,186 +45,185 @@ using namespace std;
namespace cv namespace cv
{ {
namespace datasets namespace datasets
{
class TRACK_votImpl : public TRACK_vot
{
public:
//Constructor
TRACK_votImpl()
{ {
activeDatasetID = 1; class TRACK_votImpl : public TRACK_vot
frameCounter = 0; {
} public:
//Destructor //Constructor
virtual ~TRACK_votImpl() {} TRACK_votImpl()
{
//Load Dataset activeDatasetID = 1;
virtual void load(const string &path); frameCounter = 0;
}
//Destructor
virtual ~TRACK_votImpl() {}
virtual int getDatasetsNum(); //Load Dataset
virtual void load(const string &path);
virtual int getDatasetLength(int id); virtual int getDatasetsNum();
virtual bool initDataset(int id); virtual int getDatasetLength(int id);
virtual bool getNextFrame(Mat &frame); virtual bool initDataset(int id);
virtual vector <Point2d> getGT(); virtual bool getNextFrame(Mat &frame);
private: virtual vector <Point2d> getGT();
void loadDataset(const string &path);
string numberToString(int number); private:
}; void loadDataset(const string &path);
void TRACK_votImpl::load(const string &path) string numberToString(int number);
{ };
loadDataset(path);
}
string TRACK_votImpl::numberToString(int number) void TRACK_votImpl::load(const string &path)
{ {
string out; loadDataset(path);
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) string TRACK_votImpl::numberToString(int number)
{ {
ifstream namesList(rootPath + "/list.txt"); string out;
//ifstream lengthsList(rootPath + "/lengths.txt"); char numberStr[9];
vector <int> datasetsLengths; sprintf(numberStr, "%u", number);
string datasetName; for (unsigned int i = 0; i < 8 - strlen(numberStr); ++i)
{
out += "0";
}
out += numberStr;
return out;
}
if (namesList.is_open()) inline bool fileExists(const std::string& name)
{ {
int currDatasetID = 0; struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}
//All datasets/folders loop void TRACK_votImpl::loadDataset(const string &rootPath)
while (getline(namesList, datasetName))
{ {
currDatasetID++; ifstream namesList(rootPath + "/list.txt");
vector <Ptr<TRACK_votObj> > objects; //ifstream lengthsList(rootPath + "/lengths.txt");
vector <int> datasetsLengths;
string datasetName;
//All frames/images loop if (namesList.is_open())
Ptr<TRACK_votObj> currDataset(new TRACK_votObj); {
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!!!";
}
//Open dataset's ground truth file namesList.close();
ifstream gtList(rootPath + "/" + datasetName + "/groundtruth.txt"); return;
if (!gtList.is_open()) }
cout << "Error to open groundtruth.txt!!!";
//Make a list of datasets lengths int TRACK_votImpl::getDatasetsNum()
int currFrameID = 1; {
if (currDatasetID == 0) return data.size();
cout << "VOT 2015 Dataset Initialization...\n"; }
do int TRACK_votImpl::getDatasetLength(int id)
{
if (id > 0 && id <= (int)data.size())
return data[id - 1].size();
else
{ {
currFrameID++; cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl;
string fullPath = rootPath + "/" + datasetName + "/" + numberToString(currFrameID) + ".jpg"; return -1;
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(); bool TRACK_votImpl::initDataset(int id)
return; {
} if (id > 0 && id <= (int)data.size())
{
int TRACK_votImpl::getDatasetsNum() activeDatasetID = id;
{ return true;
return data.size(); }
} else
{
int TRACK_votImpl::getDatasetLength(int id) cout << "Dataset ID is out of range...\n " << "Allowed IDs are: 1~" << (int)data.size() << endl;
{ return false;
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() bool TRACK_votImpl::getNextFrame(Mat &frame)
{ {
return Ptr<TRACK_votImpl>(new TRACK_votImpl); frame = imread(data[activeDatasetID - 1][frameCounter]->imagePath);
} frameCounter++;
return !frame.empty();
}
vector <Point2d> TRACK_votImpl::getGT() Ptr<TRACK_vot> TRACK_vot::create()
{ {
Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1][frameCounter - 1]; return Ptr<TRACK_votImpl>(new TRACK_votImpl);
return currObj->gtbb; }
}
} vector <Point2d> TRACK_votImpl::getGT()
} {
Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1][frameCounter - 1];
return currObj->gtbb;
}
}
}
\ No newline at end of file
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