对于某些人来说,这可能是一个琐碎的问题。但是我有几天的怀疑了。我必须逐帧读取视频文件。 .csv
文件包含有关其相应行中的帧的信息。
我想在单个循环中组合下面的代码,即视频和.csv
文件的读取,以使帧的相应信息在各行中保存有正确的信息。
//1. This is used for reading a video file frame by frame
for (;;) {
auto pair = video->Read();
cv::Mat frame = pair.first;
int frame_idx = pair.second;
if (frame.empty()) break;
......
}
//2. This is for reading a csv file line by line
fstream fin;
// Open an existing file
fin.open("reportcard.csv", ios::in);
// Read the Data from the file as String Vector
vector<string> row;
string line, word, temp;
while (fin >> temp)
{
row.clear();
// read an entire row and
// store it in a string variable 'line'
getline(fin, line);
// used for breaking words
stringstream s(line);
// read every column data of a row and store it in a string variable, 'word'
while (getline(s, word, ', '))
{
// add all the column data
// of a row to a vector
row.push_back(word);
}
// Print the found data
cout << "Frame number " << row[0] << "\n";
cout << "Detail 1: " << row[1] << "\n";
cout << "Detail 2: " << row[2] << "\n";
cout << "Detail 3: " << row[3] << "\n";
}
实现此任务的最有效方法是什么?任何建议和帮助将不胜感激。预先感谢。
如果您的数据以相同的顺序到达,则可以只合并两个循环的主体。