Ask Your Question
0

How do I convert vector<Point> to vector<Point2f>

asked 2018-03-24 10:05:37 -0600

wrxx gravatar image

I have vector<Point> contour and want to convert it to vector<Point2f>.

What seems to work is

vector<Point2f> contour2f; 
for (int j = 0; j < contour.size(); j++) {
    contour2f.push_back((Point2f)contour[j]); 
}

Is there a better way of doing this (more elegant)?

edit retag flag offensive close merge delete

Comments

in short: NO.

berak gravatar imageberak ( 2018-03-24 10:30:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-26 08:43:28 -0600

mnme gravatar image

I couldn't find a way to do it more elegant, but here is a solution with C++11. Maybe it is useful to someone.

vector<Point> contours = ...;
vector<Point2f> contours2f;
std::transform(contours.begin(), contours.end(),
               std::back_inserter(contours2f),
               [](const Point& p) { return (Point2f)p; });

This assumes that std::transform does the transformation in order.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-24 10:05:37 -0600

Seen: 3,324 times

Last updated: Mar 24 '18