opencv python 文档,OpenCV Python API的文件存储

I'm currently using FileStorage class for storing matrices XML/YAML using OpenCV C++ API.

However, I have to write a Python Script that reads those XML/YAML files.

I'm looking for existing OpenCV Python API that can read the XML/YAML files generated by OpenCV C++ API

解决方案

You can use PyYAML to parse the YAML file.

Since PyYAML doesn't understand OpenCV data types, you need to specify a constructor for each OpenCV data type that you are trying to load. For example:

import yaml

def opencv_matrix(loader, node):

mapping = loader.construct_mapping(node, deep=True)

mat = np.array(mapping["data"])

mat.resize(mapping["rows"], mapping["cols"])

return mat

yaml.add_constructor(u"tag:yaml.org,2002:opencv-matrix", opencv_matrix)

Once you've done that, loading the yaml file is simple:

with open(file_name) as fin:

result = yaml.load(fin.read())

Result will be a dict, where the keys are the names of whatever you saved in the YAML.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值