Ask Your Question
0

allocating a class member vector of points in the constructor

asked 2013-01-01 10:17:20 -0600

avi555 gravatar image

Hello, I'm new to the opencv and to C++. I declared a public class member that is a vector of points vector<point> hull; now i'm initializing it in the constructor like this: vector<vector<point> >hull( contours.size() ); These is from the OpenCV tutorial. Now i want to draw the hull, but nothing . and the hull.size() return 0. I'm sure that it is a wrong C++ doing, but i couldn't how to do it right. Thanks for any help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-01-01 11:10:20 -0600

ZachTM gravatar image

updated 2013-01-01 11:14:01 -0600

vector<vector<point> >hull( contours.size() ); does not initialize the vector with all the contours data. What you want to do is probably :

vector<vector<point> >hull();
hull.insert(hull.begin(),contours.begin(),contours.end());

That will copy all the contents of contours into hull, which is how I do it. Vectors aren't like arrays in C++ because they are dynamic, so when you use hull.size(), it returns zero because you haven't put anything into the vector yet. I hope that helps!

edit flag offensive delete link more

Comments

Thanks ZachTM, well i forgot to post the line convexHull( Mat(contours[i]), hull[i], false ); this line comes after the declaration in the constructor. Thanks again

avi555 gravatar imageavi555 ( 2013-01-01 16:25:45 -0600 )edit

Question Tools

Stats

Asked: 2013-01-01 10:17:20 -0600

Seen: 171 times

Last updated: Jan 01 '13