Ask Your Question
0

decomposing Points

asked 2014-09-13 07:50:47 -0500

mikel gravatar image

updated 2014-09-13 08:41:32 -0500

berak gravatar image

I have a vector of Point2f and I would like to work with the x and y values separately. Is there an easy way to change something like vector<point2f> into a Mat with the x and y as separate columns?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-13 08:03:22 -0500

berak gravatar image

updated 2014-09-13 08:05:12 -0500

// 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 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]
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-13 07:50:47 -0500

Seen: 130 times

Last updated: Sep 13 '14