Calculating convexityDefects using OpenCV 2.4 in c++

From openCV wiki :

Finds the convexity defects of a contour.

So you should include it in your loop.

std::vector<Vec4i> defects; 
vector<cv::vector<int> >hull( contours.size() );

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

Also, as you mentioned, in wiki is said:

hull – Output convex hull. It is either an integer vector of indices
or vector of points. In the first case, the hull elements are 0-based
indices of the convex hull points in the original array (since the set
of convex hull points is a subset of the original point set). In the
second case, hull elements are the convex hull points themselves.

Leave a Comment