2017-03-29 83 views
0

我曾經使用opencv C++的FileStorage類,它非常有用,但我找不到如何在opencv python中使用它。請幫幫我。感謝如何使用cv2.FileStorage

+0

是這樣的:'FS = cv2.FileStorage( 「foo.yml」,0)fs.getNode( 「酒吧」 ).mat()'shuld工作... – Miki

+0

謝謝,但如何寫? –

回答

0
`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 ]