bool LoadTxt2Vec(string path, string sep, vector<vector<float>>& data)
{
data.clear();
int length;
char* buffer;
ifstream inf(path, ios::binary);
inf.seekg(0, ios::end);
length = inf.tellg();
inf.seekg(0, ios::beg);
if (length < 1) return 0;
buffer = new char[length];
inf.read(buffer, length);
string str = buffer;
int pos0 = 0;
int pos = str.find('\r\n', pos0);
stringstream Oss;
float Result;
vector<float> num;
while (pos <str.size() && pos>-1 && pos != pos0)
{
string str1 = str.substr(pos0, pos - pos0) + sep;
int pos2 = 0;
int pos1 = str1.find(sep, pos2);
while (pos1 <str1.size() && pos1>-1 && pos1 != pos2)
{
string str2 = str1.substr(pos2, pos1 - pos2);
int i = 0, j = 0;
bool b = 0;
for (; i<str2.size(); i++)
{
if ((str2[i] <= '9' && str2[i] >= '0') || str2[i] == '+' || str2[i] == '-') break;
else j++;
}
for (i++; i<str2.size(); i++)
{
if (!((str2[i] <= '9' && str2[i] >= '0') || str2[i] == '.' || str2[i] == 'e' || str2[i] == 'E')) break;
else if (str2[i] == 'e' || str2[i] == 'E')
{
if (i == str2.size() || !(str2[i] <= '9' && str2[i] >= '0' || str2[i] == '-') || b) break;
b = 1;
}
}
string str3 = str2.substr(j, i - j);
Oss << str3;
Oss >> Result;
Oss.clear();
num.push_back(Result);
pos2 = pos1 + sep.size();
pos1 = str1.find(sep, pos2);
}
pos0 = pos + 2;
data.push_back(num);
num.clear();
pos = str.find('\r\n', pos0);
}
return 1;
}
void Gamma(Mat& src, double gamma) { uchar lutData[256]; float value; for (int i = 0; i<256; i++) { value = pow((float)i / 255.0f, gamma)*255.0f; if (value>255) value = 255; if (value<0) value = 0; lutData[i] = (uchar)value; } Mat lut(1, 256, CV_8UC1, lutData); LUT(src, lut, src); }
|