Ask Your Question
0

Python Load OpenCV FileStorage

asked 2012-08-21 17:23:53 -0600

Eric gravatar image

updated 2012-08-22 10:07:11 -0600

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"

edit retag flag offensive close merge delete

Comments

Anyone ? Same problem with XML format.

Eric gravatar imageEric ( 2012-08-22 07:46:38 -0600 )edit

post some snippet of code anyway

yes123 gravatar imageyes123 ( 2012-08-22 08:19:41 -0600 )edit

I add a sample file.

Eric gravatar imageEric ( 2012-08-22 10:08:01 -0600 )edit

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

Eric gravatar imageEric ( 2012-08-23 10:10:56 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2012-11-08 16:11:37 -0600

alexcv gravatar image

updated 2012-11-08 16:16:52 -0600

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

edit flag offensive delete link more
0

answered 2017-07-28 09:08:11 -0600

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())
edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-08-21 17:23:53 -0600

Seen: 8,798 times

Last updated: Dec 10 '12