I am trying get Convexity Defects from the following code, but keep getting a unhandled exception. What am I doing wrong?
vector<Vec4i> defects;
ContourPoly = vector<Point>(contour.size());
approxPolyDP( Mat(contour), ContourPoly,20, false );
convexHull(Mat(ContourPoly), HullPoints, false, true);
// The following line wont work
convexityDefects(Mat(ContourPoly),HullPoints,defects);
While HullPoints are of type vector<Point>
The exception is as follows
OpenCV Error: Assertion Failed (ptnum >3) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1969
But with vector<Point> defects;
or vector<Vec4i> defects
I get the following exception
OpenCV Error: Assertion Failed (hull.checkVector(1,CV_32S) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1971
First of all
should be:
Also, before calling
convexityDefects
function, check if the size of theHullPoints
is greater than 3.