如何使用cv2.FileStorage

时间:2017-03-29 12:26:09

标签: python opencv opencv3.1

我习惯使用opencv c ++中的FileStorage类,它非常有用,但我无法在opencv python中找到它的使用方法。请帮我。感谢

1 个答案:

答案 0 :(得分:2)

`import cv2
 import numpy as np
 f = cv2.FileStorage('test.yml',flags=1)
 a = np.zeros((10,10),dtype=np.uint8)
 f.write(name='matrix',value=a)
 f.release()
`

结果是'test.yml' “

%YAML:1.0
---
matrix: !!opencv-matrix
   rows: 10
   cols: 10
   dt: u
   data: [ 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, 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 ]