我正在尝试读取YAML文件的序列,并在一行中调整它们的形状,然后尝试在一个YAML文件中进行串联。这是我的代码片段:
for (int i = 1; i <= 6; i++ )
{
sprintf_s(filename, "VocabularyLBP/Dictionary%d.yml", i);
Mat feature;// , labels);;// = Mat::zeros(1, 100, CV_32FC1);
FileStorage fs(filename, FileStorage::READ);
fs["vocabulary"] >> feature;
feature.convertTo(feature, CV_32FC1);
feature = feature.reshape(1, 1);
trainData.push_back(feature);
FileStorage fs1("trainData.yml", FileStorage::WRITE);
fs1 << "vocabulary" << trainData;
}
我没有收到错误,但得到的数据如下:
---
vocabulary: !!opencv-matrix
rows: 6
cols: 7800
dt: f
data: [ -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
-1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
-1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
%YAML:1.0
-1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
-1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
-1.32703932e-03, -1.32703932e-03, -1.32703932e-03,........
我在这里做错了什么?为什么每一行和每一列都有相同的值?
我的数据就像 数据1
%YAML:1.0
Vocabulary: !!opencv-matrix
rows: 100
cols: 78
dt: f
data: [ 5.49666524e-001, 5.66434860e-001, 4.44352776e-001,
3.23528647e-001, 2.49731302e-001, 9.43774283e-002,
8.07617828e-002, 1.17960289e-001, 6.93683475e-002,....
data2:
%YAML:1.0
Vocabulary: !!opencv-matrix
rows: 100
cols: 78
dt: f
data: [ 1.19325793e+000, 1.14433956e+000, 1.22386146e+000,
1.20958960e+000, 1.75026524e+000, 5.27490759e+000,......
data3:
%YAML:1.0
Vocabulary: !!opencv-matrix
rows: 100
cols: 78
dt: f
data: [ 3.21339786e-001, 2.84904152e-001, 2.93418944e-001,
2.12616310e-001, 1.51279286e-001, 1.42454490e-001,
1.66635603e-001,...........
等
为什么我不能在单个文件中正确获取数据?我的代码有什么问题?为什么我的代码在所有7800列和6行中都复制-1.32703932e-03?