0
vector<Point> hull; vector<Point> defects; convexHull(Mat(largest),hull,false); convexityDefects(largest,hull,defects); 

*largest is my largest contour in the image

But the convexityDefects gives me this error "Assertion failed (hull.checkVector(1, CV_32S) > 2)". Someone please help me, I do not want to resort to using C solution.

EDITED

vector<int> hull; vector<Point> defects; convexHull(Mat(largest),hull,false); vector<vector<int>> testhull; testhull.push_back(hull); convexityDefects(largest,testhull,defects); 

I tried making it with the type vector<vector<int>> before passing it to convexityDefects but convexityDefects is still giving me error "Assertion failed (ptnum > 3)..".

2 Answers 2

4

for hull you should use a vector of vectors like this:

vector<vector<Point>> hullsP( contours.size() ); vector<vector<int> > hullsI(contours.size()); 

and pass the "int" type to covexityDefects.like this :

vector<vector<Vec4i>> convdefect(contours.size()); for( int i = 0; i < contours.size(); i++ ) { convexHull( Mat(contours[i]), hullsP[i], false ); convexHull( Mat(contours[i]), hullsI[i], false ); if(hullsI[i].size() > 3 ) convexityDefects(contours[i],hullsI[i],convdefect[i]); } 
Sign up to request clarification or add additional context in comments.

Comments

2

The second argument of convexityDefects has to be the type of vector<vector<int>, while yours is vector<Point>.

2 Comments

I have made some changes to my codes, please check again on the first post. Thanks.
@user1434759 I have googled answer to all your problems very quickly. Did you try to google before asking? stackoverflow.com/questions/10620981/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.