从Java中的opencv_core.FileStorage读取opencv_core.Mat

时间:2015-04-07 13:40:31

标签: java xml opencv

就像在主题中一样,我不知道如何从我的.xml文件中读取数据。我已经使用FileStorage类(使用opencv_core.write方法)将数据写入XML文件,但现在我想将这些数据读入两个Mat(数据分为两个标签 - " TrainingData"和" TrainingLabels&#34)。

以下是代码:

opencv_core.FileStorage fs = new opencv_core.FileStorage("SVM.xml", opencv_core.FileStorage.READ);

opencv_core.Mat SVM_TrainingData = new opencv_core.Mat();
opencv_core.Mat SVM_Classes = new opencv_core.Mat();

opencv_core.FileNode dataNode = new FileNode();
opencv_core.FileNode labelsNode = new FileNode();
dataNode = fs.get("TrainingData");
labelsNode = fs.get("TrainingLabels");


opencv_core.read(dataNode, SVM_TrainingData);
opencv_core.read(labelsNode, SVM_Classes);

但是在这之后这些Mat是空的......而且我不知道如何解决这个问题。

XML看起来像这样:

<?xml version="1.0"?>
<opencv_storage>
<TrainingData type_id="opencv-matrix">
<rows>151</rows>
<cols>4752</cols>
<dt>u</dt>
<data>
0 0 28 58 64 62 57 45 37 37 48 61 64 65 66 64 65 67 65 62 61 61 60
61 59 60 58 60 58 54 56 56 53 51 47 51 48 47 43 45 43 43 42 40 39 38
...
219 232 234 239 238 233 173 121 91 38 19 19 21</data></TrainingData>
<TrainingLabels type_id="opencv-matrix">
<rows>151</rows>
<cols>1</cols>
<dt>i</dt>
<data>
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</data></TrainingLabels>
</opencv_storage>

将这些数据读入两个Mat的任何帮助都会很棒!

0 个答案:

没有答案