1 | initial version |
It seems that versions prior 3.0.0 do not have all FileStorage functionality implemented.
With version 3.2.0 (and probably all versions after 3.0.0, though I cannot say this for sure) this is no longer an issue, and all functionality we have in C++ is available in Python:
#WRITE
import numpy as np
import cv2
#writes array to .yml file
fs_write = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_WRITE)
arr = np.random.rand(5, 5)
fs_write.write("floatdata", arr)
fs_write.release()
#READ
fs_read = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_READ)
arr_read = fs_read.getNode('floatdata').mat()
fs_read.release()
File new_data.yml
%YAML:1.0
---
floatdata: !!opencv-matrix
rows: 5
cols: 5
dt: d
data: [ 1.3500562315570286e-01, 4.7332616739188160e-01,
7.8148724556477256e-01, 4.8515006212291845e-01,
5.3108316657166643e-03, 5.1800356136308345e-01,
5.2698594923003850e-01, 8.9589801430966309e-01,
6.9622407992566360e-01, 5.5301612450395854e-01,
8.9349016065812470e-02, 2.8443956686746197e-01,
8.1107151570238600e-01, 7.3436559904175847e-01,
9.4856255619457663e-01, 7.3314420186072704e-02,
6.5936190066337430e-01, 7.2222393075622360e-01,
1.9542185396859713e-01, 7.4787561019454296e-01,
3.1387065197283182e-01, 9.0187470903492872e-01,
2.2941454258655292e-01, 2.2337840652562313e-01,
2.6424822339902743e-01 ]
Array read from file:
In [23]: arr_read
Out[23]:
array([[ 0.13500562, 0.47332617, 0.78148725, 0.48515006, 0.00531083],
[ 0.51800356, 0.52698595, 0.89589801, 0.69622408, 0.55301612],
[ 0.08934902, 0.28443957, 0.81107152, 0.7343656 , 0.94856256],
[ 0.07331442, 0.6593619 , 0.72222393, 0.19542185, 0.74787561],
[ 0.31387065, 0.90187471, 0.22941454, 0.22337841, 0.26424822]])
2 | No.2 Revision |
It seems that versions prior 3.0.0 do not have all FileStorage functionality implemented.
With version 3.2.0 (and probably all versions after 3.0.0, though I cannot say this for sure) this is no longer an issue, and all functionality we have in C++ is available in Python:
#WRITE
import numpy as np
import cv2
#writes array to .yml file
fs_write = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_WRITE)
arr = np.random.rand(5, 5)
fs_write.write("floatdata", arr)
fs_write.release()
#READ
fs_read = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_READ)
arr_read = fs_read.getNode('floatdata').mat()
fs_read.release()
File new_data.yml
%YAML:1.0
---
floatdata: !!opencv-matrix
rows: 5
cols: 5
dt: d
data: [ 1.3500562315570286e-01, 4.7332616739188160e-01,
7.8148724556477256e-01, 4.8515006212291845e-01,
5.3108316657166643e-03, 5.1800356136308345e-01,
5.2698594923003850e-01, 8.9589801430966309e-01,
6.9622407992566360e-01, 5.5301612450395854e-01,
8.9349016065812470e-02, 2.8443956686746197e-01,
8.1107151570238600e-01, 7.3436559904175847e-01,
9.4856255619457663e-01, 7.3314420186072704e-02,
6.5936190066337430e-01, 7.2222393075622360e-01,
1.9542185396859713e-01, 7.4787561019454296e-01,
3.1387065197283182e-01, 9.0187470903492872e-01,
2.2941454258655292e-01, 2.2337840652562313e-01,
2.6424822339902743e-01 ]
Array read from file:
In [23]: arr_read
Out[23]:
array([[ 0.13500562, 0.47332617, 0.78148725, 0.48515006, 0.00531083],
[ 0.51800356, 0.52698595, 0.89589801, 0.69622408, 0.55301612],
[ 0.08934902, 0.28443957, 0.81107152, 0.7343656 , 0.94856256],
[ 0.07331442, 0.6593619 , 0.72222393, 0.19542185, 0.74787561],
[ 0.31387065, 0.90187471, 0.22941454, 0.22337841, 0.26424822]])
To know which OpenCV version you are using in python, type in:
import cv2
cv2.__version__
3 | No.3 Revision |
It seems that versions prior to 3.0.0 do not have all FileStorage functionality implemented.
With version 3.2.0 (and probably all versions after 3.0.0, though I cannot say this for sure) this is no longer an issue, and all functionality we have in C++ is available in Python:
#WRITE
import numpy as np
import cv2
#writes array to .yml file
fs_write = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_WRITE)
arr = np.random.rand(5, 5)
fs_write.write("floatdata", arr)
fs_write.release()
#READ
fs_read = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_READ)
arr_read = fs_read.getNode('floatdata').mat()
fs_read.release()
File new_data.yml
%YAML:1.0
---
floatdata: !!opencv-matrix
rows: 5
cols: 5
dt: d
data: [ 1.3500562315570286e-01, 4.7332616739188160e-01,
7.8148724556477256e-01, 4.8515006212291845e-01,
5.3108316657166643e-03, 5.1800356136308345e-01,
5.2698594923003850e-01, 8.9589801430966309e-01,
6.9622407992566360e-01, 5.5301612450395854e-01,
8.9349016065812470e-02, 2.8443956686746197e-01,
8.1107151570238600e-01, 7.3436559904175847e-01,
9.4856255619457663e-01, 7.3314420186072704e-02,
6.5936190066337430e-01, 7.2222393075622360e-01,
1.9542185396859713e-01, 7.4787561019454296e-01,
3.1387065197283182e-01, 9.0187470903492872e-01,
2.2941454258655292e-01, 2.2337840652562313e-01,
2.6424822339902743e-01 ]
Array read from file:
In [23]: arr_read
Out[23]:
array([[ 0.13500562, 0.47332617, 0.78148725, 0.48515006, 0.00531083],
[ 0.51800356, 0.52698595, 0.89589801, 0.69622408, 0.55301612],
[ 0.08934902, 0.28443957, 0.81107152, 0.7343656 , 0.94856256],
[ 0.07331442, 0.6593619 , 0.72222393, 0.19542185, 0.74787561],
[ 0.31387065, 0.90187471, 0.22941454, 0.22337841, 0.26424822]])
To know which OpenCV version you are using in python, type in:
import cv2
cv2.__version__
4 | No.4 Revision |
It seems that versions prior to 3.0.0 do not have all FileStorage functionality implemented.
With After version 3.2.0 (and probably all versions after 3.0.0, though I cannot say this for sure) this is no longer an issue, and all functionality we have in C++ is available in Python:
#WRITE
import numpy as np
import cv2
#writes array to .yml file
fs_write = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_WRITE)
arr = np.random.rand(5, 5)
fs_write.write("floatdata", arr)
fs_write.release()
#READ
fs_read = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_READ)
arr_read = fs_read.getNode('floatdata').mat()
fs_read.release()
File new_data.yml
%YAML:1.0
---
floatdata: !!opencv-matrix
rows: 5
cols: 5
dt: d
data: [ 1.3500562315570286e-01, 4.7332616739188160e-01,
7.8148724556477256e-01, 4.8515006212291845e-01,
5.3108316657166643e-03, 5.1800356136308345e-01,
5.2698594923003850e-01, 8.9589801430966309e-01,
6.9622407992566360e-01, 5.5301612450395854e-01,
8.9349016065812470e-02, 2.8443956686746197e-01,
8.1107151570238600e-01, 7.3436559904175847e-01,
9.4856255619457663e-01, 7.3314420186072704e-02,
6.5936190066337430e-01, 7.2222393075622360e-01,
1.9542185396859713e-01, 7.4787561019454296e-01,
3.1387065197283182e-01, 9.0187470903492872e-01,
2.2941454258655292e-01, 2.2337840652562313e-01,
2.6424822339902743e-01 ]
Array read from file:
In [23]: arr_read
Out[23]:
array([[ 0.13500562, 0.47332617, 0.78148725, 0.48515006, 0.00531083],
[ 0.51800356, 0.52698595, 0.89589801, 0.69622408, 0.55301612],
[ 0.08934902, 0.28443957, 0.81107152, 0.7343656 , 0.94856256],
[ 0.07331442, 0.6593619 , 0.72222393, 0.19542185, 0.74787561],
[ 0.31387065, 0.90187471, 0.22941454, 0.22337841, 0.26424822]])
To know which OpenCV version you are using in python, type in:
import cv2
cv2.__version__
5 | No.5 Revision |
It seems that versions prior to 3.0.0 3.1.0 do not have all FileStorage functionality implemented.
After version 3.2.0 this is no longer an issue, and all functionality we have in C++ is available in Python:
#WRITE
import numpy as np
import cv2
#writes array to .yml file
fs_write = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_WRITE)
arr = np.random.rand(5, 5)
fs_write.write("floatdata", arr)
fs_write.release()
#READ
fs_read = cv2.FileStorage('new_data.yml', cv2.FILE_STORAGE_READ)
arr_read = fs_read.getNode('floatdata').mat()
fs_read.release()
File new_data.yml
%YAML:1.0
---
floatdata: !!opencv-matrix
rows: 5
cols: 5
dt: d
data: [ 1.3500562315570286e-01, 4.7332616739188160e-01,
7.8148724556477256e-01, 4.8515006212291845e-01,
5.3108316657166643e-03, 5.1800356136308345e-01,
5.2698594923003850e-01, 8.9589801430966309e-01,
6.9622407992566360e-01, 5.5301612450395854e-01,
8.9349016065812470e-02, 2.8443956686746197e-01,
8.1107151570238600e-01, 7.3436559904175847e-01,
9.4856255619457663e-01, 7.3314420186072704e-02,
6.5936190066337430e-01, 7.2222393075622360e-01,
1.9542185396859713e-01, 7.4787561019454296e-01,
3.1387065197283182e-01, 9.0187470903492872e-01,
2.2941454258655292e-01, 2.2337840652562313e-01,
2.6424822339902743e-01 ]
Array read from file:
In [23]: arr_read
Out[23]:
array([[ 0.13500562, 0.47332617, 0.78148725, 0.48515006, 0.00531083],
[ 0.51800356, 0.52698595, 0.89589801, 0.69622408, 0.55301612],
[ 0.08934902, 0.28443957, 0.81107152, 0.7343656 , 0.94856256],
[ 0.07331442, 0.6593619 , 0.72222393, 0.19542185, 0.74787561],
[ 0.31387065, 0.90187471, 0.22941454, 0.22337841, 0.26424822]])
To know which OpenCV version you are using in python, type in:
import cv2
cv2.__version__