Search code examples
c++opencvconvex-hull

OpenCV C++ cv::convexityDefects error


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


Solution

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