/*************************************************************************
LoadData:加载数据,(一般都是在训练时会用到)
输入:
const string &strFile:文件名(带路径的)
输出:
vector<string> &_vsImageFilenames:图片名称(带路径,保证能找到哦)
vector< vector<Rect> > &_vvRect:矩形区域大小
备注:(文件中一行的格式)
文件名称 矩形区域个数 x y width height x y width height
data/1.bmp 2 10 20 100 120 50 60 100 120
**************************************************************************/
void CommonFun::LoadData(const string &strFile, vector<string> &_vsImageFilenames, vector< vector<Rect> > &_vvRect)
{ifstream f;
f.open(strFile.c_str());
string s, str;
int nIndex = 0;
Rect r;
int nIndexRect = 0;
while(!f.eof())
{
getline(f,s);
if(!s.empty())
{
//printf("s=%s\n", s.c_str());
stringstream ss(str);
ss << s;
vector<Rect> vRect;
nIndex = 0;
nIndexRect = 0;
while(getline(ss, str, ' '))
{
//printf("str=%s\n", str.c_str());
if (0 == nIndex)
{
_vsImageFilenames.push_back(str);
}
else if (1 == nIndex)
{
//检测框的个数
}
else if (2 == nIndex%4)
{
r.x = atoi(str.c_str());
nIndexRect++;
}
else if (3 == nIndex%4)
{
r.y = atoi(str.c_str());
nIndexRect++;
}
else if (0 == nIndex%4)
{
r.width = atoi(str.c_str());
nIndexRect++;
}
else if (1 == nIndex%4)
{
r.height = atoi(str.c_str());
nIndexRect++;
if (4 == nIndexRect)
{
nIndexRect = 0;
vRect.push_back(r);
}
}
nIndex++;
} //while(getline(ss, str, ' '))
_vvRect.push_back(vRect);
}//if(!s.empty())
}//while(!f.eof())
#if 0
for (int i=0; i<_vsImageFilenames.size(); i++)
{
printf("index=%d, name=%s\n", i+1, _vsImageFilenames[i].c_str());
}
for (int i=0; i<_vvRect.size(); i++)
{
for (int j=0; j<_vvRect[i].size(); j++)
{
r = _vvRect[i][j];
printf("index=%d, rect index=%d, (%d,%d,%d,%d)\n", i+1, j+1, r.x, r.y, r.width, r.height);
}
}
#endif
}