Commit 3e0c58c5 authored by Vlad Shakhuro's avatar Vlad Shakhuro

Add labelling reading to app

parent 4f161937
...@@ -7,12 +7,22 @@ using std::string; ...@@ -7,12 +7,22 @@ using std::string;
#include <vector> #include <vector>
using std::vector; using std::vector;
#include <fstream>
using std::ifstream;
using std::getline;
#include <sstream>
using std::stringstream;
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
using cv::Rect; using cv::Rect;
#include "icfdetector.hpp" #include "icfdetector.hpp"
#include "waldboost.hpp" #include "waldboost.hpp"
using cv::adas::ICFDetectorParams;
using cv::adas::ICFDetector;
static bool read_pos_int(const char *str, int *n) static bool read_pos_int(const char *str, int *n)
{ {
int pos = 0; int pos = 0;
...@@ -45,24 +55,42 @@ static bool read_overlap(const char *str, double *overlap) ...@@ -45,24 +55,42 @@ static bool read_overlap(const char *str, double *overlap)
return true; return true;
} }
static vector< vector<Rect> > read_labelling(const string& filename) static bool read_labelling(const string& path,
vector<string>& filenames, vector< vector<Rect> >& labelling)
{ {
return vector< vector<Rect> >(); string labelling_path = path + "/gt.txt";
} string filename, line;
int x1, y1, x2, y2;
char delim;
ifstream ifs(labelling_path.c_str());
if( !ifs.good() )
return false;
static vector<string> get_filenames(const string &labelling_path) while( getline(ifs, line) )
{ {
return vector<string>(); stringstream stream(line);
stream >> filename;
filenames.push_back(path + "/" + filename);
vector<Rect> filename_labelling;
while( stream >> x1 >> y1 >> x2 >> y2 >> delim )
{
filename_labelling.push_back(Rect(x1, y1, x2, y2));
}
labelling.push_back(filename_labelling);
filename_labelling.clear();
}
return true;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if( argc == 1 ) if( argc == 1 )
{ {
printf("Usage: %s OPTIONS, where OPTIONS are:\n" printf("Usage: %s OPTIONS, where OPTIONS are:\n"
"\n" "\n"
"--labelling <path> - path to labelling\n" "--path <path> - path to dir with data and labelling\n"
" (data should be in the same directory)\n" " (labelling should have name gt.txt)\n"
"\n" "\n"
"--feature_count <count> - number of features to generate\n" "--feature_count <count> - number of features to generate\n"
"\n" "\n"
...@@ -78,14 +106,14 @@ int main(int argc, char *argv[]) ...@@ -78,14 +106,14 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
string labelling_path, model_path; string path, model_path;
ICFDetectorParams params; ICFDetectorParams params;
for( int i = 1; i < argc; ++i ) for( int i = 1; i < argc; ++i )
{ {
if( !strcmp("--labelling", argv[i]) ) if( !strcmp("--path", argv[i]) )
{ {
i += 1; i += 1;
labelling_path = argv[i]; path = argv[i];
} }
else if( !strcmp("--feature_count", argv[i]) ) else if( !strcmp("--feature_count", argv[i]) )
{ {
...@@ -144,8 +172,10 @@ int main(int argc, char *argv[]) ...@@ -144,8 +172,10 @@ int main(int argc, char *argv[])
try try
{ {
ICFDetector detector; ICFDetector detector;
vector< vector<Rect> > labelling = read_labelling(labelling_path); vector<string> filenames;
vector<string> filenames = get_filenames(labelling_path); vector< vector<Rect> > labelling;
read_labelling(path, filenames, labelling);
detector.train(filenames, labelling, params); detector.train(filenames, labelling, params);
} }
catch( const char *err ) catch( const char *err )
......
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