您必须误读YAML规范,因为您使用代码生成的内容不是YAML文件。
在YAML文件映射项必须为每定义独特的generic mapping(并且使用的是因为你没有指定一个标签的通用映射):
Definition:
Represents an associative container, where each key is unique in the
association and mapped to exactly one value. YAML places no restrictions on
the type of keys; in particular, they are not restricted to being scalars.
Example bindings to native types include Perl’s hash, Python’s dictionary,
and Java’s Hashtable.
的真正问题你试图让一个简单的YAML发射器做字符串自己写。您应该已经在C++和emitted that结构中创建了所需的数据结构,那么YAML将是正确的(假设发射器不是越野车)。
根据什么样的文件结构的选择,你可能会得到:
%YAML:1.0
- features: 1.5302167832851410e-01
- features: 1.0552208870649338e-01
- features: 1.6659785807132721e-01
- features: 2.3539969325065613e-01
- features: 2.0810306072235107e-01
- features: 1.2627227604389191e-01
- features: 8.0759152770042419e-02
- features: 6.4930714666843414e-02
- features: 6.1364557594060898e-02
- features: 2.1614919602870941e-01
- features: 1.4714729785919189e-01
- features: 1.5476198494434357e-01
(单个键/值映射关系的序列)或:
%YAML:1.0
features:
- 1.5302167832851410e-01
- 1.0552208870649338e-01
- 1.6659785807132721e-01
- 2.3539969325065613e-01
- 2.0810306072235107e-01
- 1.2627227604389191e-01
- 8.0759152770042419e-02
- 6.4930714666843414e-02
- 6.1364557594060898e-02
- 2.1614919602870941e-01
- 1.4714729785919189e-01
- 1.5476198494434357e-01
(一个单一的映射关键是一个序列的单个值)
正如你经历过的,使用字符串写入为数据结构创建正确的YAML并不简单。如果你开始用合适的数据结构和发射出的结构,你也知道,你可以使用相同的结构来读回。
在我的经验,同样适用于生成XML/HTML /真CSV/INI文件,其中具有正确的数据结构并且使用发射器也避免输出格式中的错误,从而补偿初始代码的任何稍高的复杂度。
我想,以上将无法正常工作。 FileStorage基本上是一个关键值存储,您的密钥不是唯一的。什么是dest_ptr?你不能把它放入一个cv :: Mat或类似的东西吗? (也更容易回读) – berak
这些是仅限块的HOG功能。随着下面我得到全零。我想弄明白@berak – shah