First time here? Check out the FAQ!

Ask Your Question
0

Python Load OpenCV FileStorage

asked Aug 21 '12

Eric gravatar image

updated Aug 22 '12

Hi all, Is there anyway to load using python bindings a YML file containing several nodes of sequence of cvmat ? I succeed to save/load those file with c++ but I cannot make it work with python.

Any help would be appreciate!

Best,

EDIT: I add here a sample YML file which was written with opencv c++ interface, using cv::FileStorage. http://pastebin.com/YhrecFLr

With opencv python, the documentation says: Use cv.Load(filename, memstorage=None, str=None)

But I cannot make it work, it always throw "cv2.error: The node does not represent a user object"

Preview: (hide)

Comments

Anyone ? Same problem with XML format.

Eric gravatar imageEric (Aug 22 '12)edit

post some snippet of code anyway

yes123 gravatar imageyes123 (Aug 22 '12)edit

I add a sample file.

Eric gravatar imageEric (Aug 22 '12)edit

is there Python bindings for all c++ methods ? FileStorage seems to exist with python but maybe it is not complete ?

Eric gravatar imageEric (Aug 23 '12)edit

2 answers

Sort by » oldest newest most voted
1

answered Nov 8 '12

alexcv gravatar image

updated Nov 8 '12

Hi, The solution seems easy when found ;o) I hope doc will be extnded soon !

Here is how to load and use a matrix stored in an opencv generated xml file :

#load xml file
fileToLoad="myFile.xml"
myLoadedData = cv.Load(fileToLoad)

#check data properties
print myLoadedData # this print shows matrix size, datatype, cool !

#access a cell of the matrix
rowIdx=1
colIdx=10
print "Accessing matrix at col:"+str(colIdx)+", row:"+str(rowIdx)
print myLoadedData[rowIdx, colIdx]

That's done ! Hope it helps

Regards

Preview: (hide)
0

answered Jul 28 '17

TimSC gravatar image

Conventions in OpenCV 3.2 seem to be a little different to the other answers. I've used this with success:

import cv2
fs = cv2.FileStorage("calibration.xml", cv2.FILE_STORAGE_READ)
fn = fs.getNode("Camera_Matrix")
print (fn.mat())
Preview: (hide)

Question Tools

Stats

Asked: Aug 21 '12

Seen: 9,004 times

Last updated: Dec 10 '12