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
Asked
Active
Viewed 7,386 times
2
-
2Something 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 Answers
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
-
-
Please, refer to the cv::FileStorage::Mode in https://docs.opencv.org/3.1.0/d4/da4/group__core__xml.html#ga973e41cb75ef6230412a567723b7482d – 장철훈 Apr 20 '18 at 23:07
-
Assuming the enum is defined **with no explicit values** it is WRITE. Is that right? – MaciekS Apr 21 '18 at 11:12