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)..".

XterNalz
  • 325
  • 1
  • 5
  • 10

2 Answers2

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]);
}
ABSSH
  • 110
  • 5
2

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

ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
  • I have made some changes to my codes, please check again on the first post. Thanks. – XterNalz Aug 07 '12 at 08:16
  • @user1434759 I have googled answer to all your problems very quickly. Did you try to google before asking? http://stackoverflow.com/questions/10620981/calculating-convexitydefects-using-opencv-2-4-in-c – ArtemStorozhuk Aug 07 '12 at 08:51