Ask Your Question
-1

Print Mat values out to screen and vice versa

asked 2013-10-14 04:13:10 -0600

newBee gravatar image

updated 2013-10-14 04:20:21 -0600

berak gravatar image

How can I break Mat into readable format i.e get the row and column values printed and convert that readable value back to Mat again

I want something like this Eg

Mat something;
printf(something) = {{0,0},{0,1},{1,0},{1,1}...etc}

and now convert those back to Mat

{0,0},{0,1},{1,0},{1,1}...etc}=> something

I tried using this

for(int i=0 ; i<something.rows ; i++){
    for(int j=0 ; j<something.cols ; j++){
        printf("something rows and cols: %d %d \n", something.row(i),something.row(j));
    }
}

But I am getting same values

1124057088 2
1124057088 2
1124057088 2
1124057088 2
1124057088 2
1124057088 2
1124057088 2

Any help is appreciated

edit retag flag offensive close merge delete

Comments

2
  • cout << some_mat; // will probably do what you want
  • time to read a bit , i guess.
  • convert it back ? that needs some explanation
berak gravatar imageberak ( 2013-10-14 04:30:26 -0600 )edit

Thanks for the info, but how do i get into a string ? and from string back to mat ??

newBee gravatar imagenewBee ( 2013-10-14 05:57:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-14 15:20:16 -0600

Andrey Pavlenko gravatar image

Probably the following code will give you an idea:

//==== storing data ====
FileStorage fs(".xml", FileStorage::WRITE + FileStorage::MEMORY);
fs << "date" << date_string << "mymatrix" << mymatrix;
string buf = fs.releaseAndGetString();

//==== reading it back ====
FileStorage fs(buf, FileStorage::READ + FileStorage::MEMORY);
fs["date"] >> date_string;
fs["mymatrix"] >> mymatrix;
edit flag offensive delete link more

Comments

Thankz....

newBee gravatar imagenewBee ( 2013-10-15 04:17:27 -0600 )edit

Question Tools

Stats

Asked: 2013-10-14 04:13:10 -0600

Seen: 2,711 times

Last updated: Oct 14 '13