Ask Your Question

Cannot retrieve matrix from an xml file using FileStorage

asked 2016-04-10 04:09:51 -0500

bob409 gravatar image

updated 2016-04-10 04:10:44 -0500

I am storing features in form of a matrix in an xml file using FileStorage

FileStorage f("trial.xml",FileStorage::WRITE);
Mat feature;

By executing the above code, a trial.xml file is created

<?xml version="1.0"?>
<features type_id="opencv-matrix">
   3.35365832e-001 1.21951215e-002 9.14634094e-002 6.30081296e-002
    3.31300795e-001 1.01626012e-002 9.95934904e-002 5.69105670e-002</data></features>

However, I cannot retrive the matrix from the xml file.

FileStorage fs("trial.xml",FileStorage::READ);
Mat data;

The Mat data is empty: []

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-10 04:17:27 -0500

LorenaGdL gravatar image

updated 2016-04-10 05:52:03 -0500

It should be fs["features"]>>data;. Have in mind than reading a matrix is not only reading the numbers inside, but also reading its dimensions (rows and cols), type, etc.

Refer to documentation for more details and examples:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-04-10 04:09:51 -0500

Seen: 138 times

Last updated: Apr 10 '16