Ask Your Question

# Revision history [back]

you can use reshape , to adjust it without copying anything (it just changes rows/cols members of the Mat):

// demo vector
vector<float> f {1,2,3,4,5};
Mat m(f, true); // deep copy (if you wanted that, - use false, if you did not) !

// now we have a single column:
cerr << m << endl;
[1;
2;
3;
4;
5]

// let's reshape it to a single row:
m = m.reshape(1,1);
cerr << m << endl;
[1, 2, 3, 4, 5]

// and, just for the show, back to a column:
m = m.reshape(1, m.total());
cerr << m << endl;
[1;
2;
3;
4;
5]


you can use reshape , to adjust it without copying anything data internally (it just changes rows/cols members of the Mat):

// demo vector
vector<float> f {1,2,3,4,5};
Mat m(f, true); // deep copy (if you wanted that, - use false, if you did not) !

// now we have a single column:
cerr << m << endl;
[1;
2;
3;
4;
5]

// let's reshape it to a single row:
m = m.reshape(1,1);
cerr << m << endl;
[1, 2, 3, 4, 5]

// and, just for the show, back to a column:
m = m.reshape(1, m.total());
cerr << m << endl;
[1;
2;
3;
4;
5]