Ask Your Question
0

drawContours vector<Point>

asked 2015-08-17 10:41:20 -0500

Nbb gravatar image

Hello forum,

I have a vector of class Object , each containing a single contour.

vector<Object> People;

Class Object {

private:
vector<Point> contour;

public:
vector<Point> get_Contour { return contour; }
};

I am having problems trying to draw the contour using the drawContours function

for (int i = 0; i < People.size(); i++)
            drawContours(display, People[i].get_Contour(), -1, Scalar(255, 255, 255), 1, 8, noArray(), 2147483647 , Point());

OpenCV Error: Assertion failed (i < 0) in cv::_InputArray::getMat_, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line 1151

How its done in the tutorial is that a vector< vector< Point>> is passed. However I only have one contour, a vector< Point>. I hope I can get some help on this.

edit retag flag offensive close merge delete

Comments

may be you can use polylines instead of drawContours

polylines(display, People[i].get_Contour(),true, Scalar(255, 255, 255));
LBerger gravatar imageLBerger ( 2015-08-17 11:02:14 -0500 )edit

Hello, thanks for the reply. However, I need to be able to offset ( Point(x,y) ) the contours as it's coordinates / midpoint is calculated by another function, Do you think I should just use vector<vector<point>> contour but with only 1 contour stored ?

Nbb gravatar imageNbb ( 2015-08-17 11:08:14 -0500 )edit
3

Yes it works too like this

vector<vector< Point> > c;
c.push_back(People[i].get_Contour());
drawContours(display, c, -1, Scalar(255, 255, 255), 1, 8, noArray(), 2147483647 , Point());
LBerger gravatar imageLBerger ( 2015-08-17 11:14:45 -0500 )edit

did you try in the original code instead of using -1 for the idx parameter to use the i from the People's size. Moreover, why your maxLevel parameter is set to so high value (i.e. 2147483647)?

theodore gravatar imagetheodore ( 2015-08-17 11:28:20 -0500 )edit
1

your design looks broken. what's the need for an Object class ?

berak gravatar imageberak ( 2015-08-18 00:19:01 -0500 )edit

Like @berak said, I am more convinced that you are making a huge design mistake by wrapping it inside the object class. There is about ZERO need for that right?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-18 04:52:20 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-17 12:19:38 -0500

unxnut gravatar image

Te second parameter is supposed to be InputArrayOfArrays whereas you have made it into a single vector. You should change it back to a std::vector<std::vector<cv::Point> and it should work.

edit flag offensive delete link more

Comments

Thanks, this answer helps solve my problem.

_sparkle_eyes gravatar image_sparkle_eyes ( 2019-03-02 21:28:32 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-08-17 10:41:20 -0500

Seen: 3,397 times

Last updated: Aug 17 '15