我使用PyYAML读取文件,python代码是:
with open('demo.yml') as f:
dataMap = yaml.load(f)
demo.yml:
%YAML:1.0
my_svm: !!opencv-ml-svm
svm_type: C_SVC
kernel: { type:LINEAR }
C: 1.
然后错误是:
yaml.scanner.ScannerError: while scanning a directive
in "demo.yml", line 1, column 1
expected alphabetic or numeric character, but found ':'
in "demo.yml", line 1, column 6
有人帮助我吗?
答案 0 :(得分:3)
指令应该是%YAML 1.0
(没有冒号)。您还需要一个“文档启动”(---
)来将指令与文档分开。 E.g:
%YAML 1.0
---
my_svm: !!opencv-ml-svm
svm_type: C_SVC
kernel: { type: LINEAR }
C: 1.
答案 1 :(得分:2)
您可以修改opencv 3.0创建的yaml文件 来自opencv的file1:
1 %YAML:1.0
2 my_svm: !!opencv-ml-svm
3 svm_type: C_SVC
4 kernel: { type:LINEAR }
5 C: 1.
6 ...
file2的:
1 my_svm: opencv-ml-svm
2 svm_type: C_SVC
3 kernel: { type: LINEAR }
4 C: 1.
5 ...
file1 - > file2的:
然后您可以使用yaml.load(filename)
加载数据。
答案 2 :(得分:-1)
这对我有用:
from cv2 import cv
import numpy as np
filepath = "test.yml"
matrixA = np.array( cv.Load(filepath, cv.CreateMemStorage(), "matrixA") )
matrixB = np.array( cv.Load(filepath, cv.CreateMemStorage(), "matrixB") )
print "matrixA:", matrixA
print "matrixB:", matrixB
如下所示: http://xudongai.blogspot.jp/2013/08/how-to-use-python-to-load-opencv-yml.html