I\'m currently using FileStorage class for storing matrices XML/YAML using OpenCV C++ API.
However, I have to writ
In addition to @misha's response, OpenCV YAML's are somewhat incompatible with Python.
Few reasons for incompatibility are:
a: 2
, and not a:2
for Python] The following function takes care of providing that:
import yaml
import re
def readYAMLFile(fileName):
ret = {}
skip_lines=1 # Skip the first line which says "%YAML:1.0". Or replace it with "%YAML 1.0"
with open(scoreFileName) as fin:
for i in range(skip_lines):
fin.readline()
yamlFileOut = fin.read()
myRe = re.compile(r":([^ ])") # Add space after ":", if it doesn't exist. Python yaml requirement
yamlFileOut = myRe.sub(r': \1', yamlFileOut)
ret = yaml.load(yamlFileOut)
return ret
outDict = readYAMLFile("file.yaml")
NOTE: Above response is applicable only for yaml's. XML's have their own share of problems, something I haven't explored completely.