Filestorage: how to save Mat with more columns

asked 2016-10-15 05:06:11 -0600

trucna gravatar image

Filestorage used like like this

Mat G;
...
FileStorage file_func_g_comp("func_g_comp.xml", FileStorage::WRITE);

file_func_g_comp << "MyData" << G;
file_func_g_comp.release();

stores data in xml like this

<?xml version="1.0"?>
<opencv_storage>
<MyData type_id="opencv-matrix">
  <rows>501</rows>
  <cols>501</cols>
  <dt>f</dt>
  <data>
    -2.34666206e-002 -2.34663915e-002 -2.34661158e-002 -2.34658401e-002
    -2.34655663e-002 -2.34652907e-002 -2.34650150e-002 -2.34647393e-002
    -2.34644637e-002 -2.34641880e-002 -2.34639123e-002 -2.34636385e-002
    -2.34633628e-002 -2.34630872e-002 -2.34628115e-002 -2.34625377e-002
    -2.34622620e-002 -2.34619863e-002 -2.34617107e-002 -2.34614350e-002
    -2.34611612e-002 -2.34608855e-002 -2.34606098e-002 -2.34603342e-002
    -2.34600604e-002 -2.34597847e-002 -2.34595090e-002 -2.34592333e-002
    -2.34589577e-002 -2.34586820e-002 -2.34584082e-002 -2.34581325e-002
    -2.34578568e-002 -2.34575830e-002 -2.34573074e-002 -2.34570317e-002
    -2.34567560e-002 -2.34564804e-002 -2.34562065e-002 -2.34559309e-002
    -2.34556552e-002 -2.34553814e-002 -2.34551057e-002 -2.34548301e-002
    -2.34545544e-002 -2.34542787e-002 -2.34540049e-002 -2.34537292e-002
    -2.34534536e-002 -2.34531797e-002 -2.34529041e-002 -2.34526284e-002
    -2.34523527e-002 -2.34520789e-002 -2.34518033e-002 -2.34515276e-002
    -2.34512538e-002 -2.34509781e-002 -2.34507024e-002 -2.34504268e-002
    -2.34501511e-002 -2.34498773e-002 -2.34496016e-002 -2.34493259e-002
    -2.34490521e-002 -2.34487765e-002 -2.34485008e-002 -2.34482251e-002
    -2.34479513e-002 -2.34476756e-002 -2.34474018e-002 -2.34471262e-002
    -2.34468505e-002 -2.34465748e-002 -2.34462991e-002 -2.34460253e-002
    -2.34457497e-002 -2.34454740e-002 -2.34452002e-002 -2.34449245e-002...

My problem is that I need data to be stored as a matrix 501 x 501, not like that (in four columns), for future processing in another software.

Is there a way how to do it?

edit retag flag offensive close merge delete

Comments

1

the columns in the xml file are meaningless (that's just internal formatting)

berak gravatar imageberak ( 2016-10-15 06:11:40 -0600 )edit

They are not meaningless for me, I need data in perfect match with columns and rows for 3rd party processing.

This is why I am asking, if there is a simple way how to do it and suppress this "internal OpenCV thing".

trucna gravatar imagetrucna ( 2016-10-15 06:18:00 -0600 )edit
1

yea, i see. what do you need it for ? opencv has cv::format , you could write it into a std::ifstream

i guess, cv::FileStorage is just a bad fit for your case

berak gravatar imageberak ( 2016-10-15 06:36:10 -0600 )edit

I need it for Matlab and Mathematica basically. Thank you for cv::Formatter, looks promising!

trucna gravatar imagetrucna ( 2016-10-15 15:03:15 -0600 )edit