Skip to content

Instantly share code, notes, and snippets.

@kauevestena
Last active December 4, 2015 18:36
Show Gist options
  • Save kauevestena/530fc996b2c318c46d13 to your computer and use it in GitHub Desktop.
Save kauevestena/530fc996b2c318c46d13 to your computer and use it in GitHub Desktop.
Misc SMMT2
//you shall need opencv and/or armadillo libs
//you may need to load 'kStringManip.h'
Mat loadMatrixFromXML(string filename)
{
Mat m;
FileStorage fs(filename, FileStorage::READ);
fs[subsBefChar(filename,".")] >> m;
fs.release();
return m;
}
void removeSeps(string filename,string outname,char newSeparator=' ',vector<string> separators)
{
//in some input file, you have some separators that you want to swap with an unique separator
ifstream infile(filename);
ofstream outfile(outname);
string line;
while (std::getline(infile,line))
{
for (unsigned int i=0;i<separators.size();i++)
{
replace( line.begin(), line.end(),separators[i][0],newSeparator);
}
//cout<<line<<endl;
outfile<<line<<endl;
}
infile.close();outfile.close();
}
vector<int> imgOrder(vector<string> imagelist,string before,string after)
{
//you have a vector of string with imagenames
//and in that names, inside, you have numbers between two constant names
int beg,endd;
vector<int> pos;
for (unsigned int i = 0 ; i<imagelist.size() ; i++)
{
beg = imagelist[i].find(before);beg += before.size();
endd = imagelist[i].find(after);
pos.push_back( stoi(imagelist[i].substr(beg,endd-beg)) );
}
return pos;
}
vector<string> imagelistVector(string path)
{
//function to create a vector containing the paths to a list of images in the given folder
vector<string> fn;
cv::glob(path,fn,false);
return fn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment