Question

i've already read the posts here and here but they do not solve the error i get.

My code

vector<Vec4i> defects;
vector<vector<int> >hull( contours.size() );
for (int i = 0; i < contours.size(); i++)
{
    convexHull( contours[i], hull[i], false, false );
    if(contours[i].size() > 3 )
        convexityDefects(contours[i], hull[i], defects[i]);
}

According to the posts above this should work, but it does not. I still get the error
error: (-215) hull.checkVector(1, CV_32S) > 2 in function convexityDefects
I really don't see the problem here.

Était-ce utile?

La solution

Okay, the problem was mainly because due to some odd reason i had contours so small that the hull was merely a straight line (meaning consisting only of 2 points). So the error was referencing to the size of the hull vector, other than in the other posts where it seemed to have something to do with the type of vector.

So, just replacing
if(contours[i].size() > 3 ) with if(hulls[i].size() > 2 ) works fine.

Autres conseils

As reported on opencv references:

ConvexityDefects(contour, convexhull, storage) → convexity_defects
  Finds the convexity defects of a contour.

Parameters: 
  contour (CvArr or CvSeq) – Input contour
  convexhull (CvSeq) – Convex hull obtained using ConvexHull2 that should contain pointers or indices to the contour points, not the hull points themselves (the return_points parameter in ConvexHull2 should be 0)
  storage (CvMemStorage) – Container for the output sequence of convexity defects. If it is NULL, the contour or hull (in that order) storage is used

In particular, take a look at second parameter: are you sure that is obtained using ConvexHull2?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top