txt文件示例:
读取该文件,并存入一个vector之中:
std::vector<cv::Point2f> featruePoint;
featruePoint.clear();
std::string seqname = fileList_image.substr(0, fileList_image.size() - 4);//fileList_image是txt文件对应的同名.png图像,使用 substr()取fileList_image的开始到倒数第四个字符之 间的字符。
std::string pointfile = filedir_point + seqname + ".txt";//完整的txt文件所在的路径和名称
std::ifstream infile;
infile.open(pointfile.c_str());
assert(infile.is_open());
std::string s;
while (getline(infile, s))
{
std::cout << s << std::endl;
char c = s.at(0);
if (c<'0' || c>'9')
continue;
std::stringstream ss;
ss << s;
float tmpd;
int cnt = 0;
float data[2];
while (ss >> tmpd)
{
data[cnt] = tmpd;
cnt++;
if (cnt == 2)
break;
if (ss.peek() == ',' || ss.peek() == ' ')
ss.ignore();
}
//std::cout << data[0] << std::endl;
//std::cout << data[1] << std::endl;//逗号分割开的两个值
featruePoint.push_back(cv::Point2f(data[0], data[1]));
}
infile.close();