Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
// setup demo data:
vector<Point> pv;
pv.push_back(Point(1,2));
pv.push_back(Point(3,4));
pv.push_back(Point(5,6));
pv.push_back(Point(7,8));

// make a Mat of it:
Mat m(pv);
cerr << m << endl;

// re-arrange it to a 4row, 2col, 1chan Mat:
m = m.reshape(1,4);
cerr << m << endl;

// now you can access single coloums 
cerr << m.col(0) << endl;
cerr << m.col(1) << endl;

[1, 2; 3, 4; 5, 6; 7, 8]
[1, 2;
  3, 4;
  5, 6;
  7, 8]
[1; 3; 5; 7]
[2; 4; 6; 8]
// setup demo data:
vector<Point> vector<Point2f> pv;
pv.push_back(Point(1,2));
pv.push_back(Point(3,4));
pv.push_back(Point(5,6));
pv.push_back(Point(7,8));
pv.push_back(Point2f(1,2));
pv.push_back(Point2f(3,4));
pv.push_back(Point2f(5,6));
pv.push_back(Point2f(7,8));

// make a Mat of it:
Mat m(pv);
cerr << m << endl;

// re-arrange it to a 4row, 2col, 1chan Mat:
m = m.reshape(1,4);
cerr << m << endl;

// now you can access single coloums 
cerr << m.col(0) << endl;
cerr << m.col(1) << endl;

[1, 2; 3, 4; 5, 6; 7, 8]
[1, 2;
  3, 4;
  5, 6;
  7, 8]
[1; 3; 5; 7]
[2; 4; 6; 8]
// setup demo data:
vector<Point2f> pv;
pv.push_back(Point2f(1,2));
pv.push_back(Point2f(3,4));
pv.push_back(Point2f(5,6));
pv.push_back(Point2f(7,8));

// make a Mat of it:
Mat m(pv);
cerr << m << endl;

// re-arrange it to a 4row, 2col, 1chan Mat:
m = m.reshape(1,4);
cerr << m << endl;

// now you can access single coloums cols: 
cerr << m.col(0) << endl;
cerr << m.col(1) << endl;

[1, 2; 3, 4; 5, 6; 7, 8]
[1, 2;
  3, 4;
  5, 6;
  7, 8]
[1; 3; 5; 7]
[2; 4; 6; 8]