2

I used to FileStorage class in opencv c++ and it's very useful but i can't find how to use it in opencv python. Please help me. Thanks

Tung Ha
  • 141
  • 2
  • 7
  • 2
    Something like: `fs = cv2.FileStorage("foo.yml", 0) fs.getNode("bar").mat()` shuld work... – Miki Mar 29 '17 at 13:05
  • thanks but how to write? – Tung Ha Mar 30 '17 at 07:12
  • Does this answer your question? [How to read/write a matrix from a persistent XML/YAML file in OpenCV 3 with python?](https://stackoverflow.com/questions/44056880/how-to-read-write-a-matrix-from-a-persistent-xml-yaml-file-in-opencv-3-with-pyth) – angelo-peronio Mar 07 '22 at 19:42

1 Answers1

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()
`

the result is in '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 ]
장철훈
  • 21
  • 4