how to read a YML vector in python

asked 2020-07-30 04:11:43 -0600

Ulyss gravatar image

updated 2020-07-30 06:44:28 -0600

OPENCV 4.2

I record a vector in C++

vector<float> myVector;
//... filling vector somewhere ...
name = "myVector";
// storing vector
myFileStorage << name << myVector;

This gives an YML file beginning like this:

%YAML:1.0
---
myVector: [ 0., 1.00840342e+00, 1.09243703e+02 ]

Afterward I can't retrieve this vector in python (FileNode type returns NONE) while getting Mat style is as easy as:

f= cv.FileStorage(file, cv.FILE_STORAGE_READ)
data0 = (f.getNode("data0").mat())

I've added a subroutine getting this done manually but it's a pity to not be able to retrieve it directly from FileStorage.

EDIT

@berak : Being a new user I can't reply before 2 days...

With a one-line instruction I can get back OpenCV Mat from FileStorage

For Vector I would love something like

 myVector = (f.getNode("myVector").vect())

I've not found any answer yet.

edit retag flag offensive close merge delete

Comments

I've added a subroutine getting this done manually but it's a pity to not be able to retrieve it directly from FileStorage.

unclear, what you mean here, can you explain more, please ?

berak gravatar imageberak ( 2020-07-30 04:16:10 -0600 )edit