我试图将来自XML文件的矩阵数据存储到rawFaceData向量中。当我在第一个for循环中检查cout语句时,对于向量中的所有元素,它都返回我想要的内容。但是当它跳出第一个for循环并进入第二个for循环时,cout始终给我与最后一个元素完全相同的所有元素的值(例如,如果向量大小为4,则cout会4次给我最后一个元素的值!),之前的值都消失了。有谁能告诉我为什么?谢谢!
vector<Mat> rawFaceData;
Mat temp;
FileStorage fsRead = FileStorage();
//output xml datas to a Mat vector for calculation
for(int readCount = 1; readCount < count; readCount++){
ssfilename.str("");
ssfilename<<name<<readCount<<postfix;
filename = ssfilename.str();
cout<<filename<<endl;
fsRead.open(filename, FileStorage::READ);
fsRead["ImageData"]>>temp;
rawFaceData.push_back(temp);
cout<<rawFaceData[readCount-1]<<endl;
}
//now raw image datas are now all in the Mat vector, there are count-1 elements in this vector.
//following is avg calculation of the training images.
for(int i = 0; i < rawFaceData.size(); i++){
cout<<rawFaceData[i]<<"\n"<<endl;
}
Mat
类的定义和实现。听起来它似乎没有适当的值语义。 - Benjamin Lindley