I'm writing C (not C++) code to run convex hull on contours of rectangles. The (greatly simplified) code for that looks like this:
CvSeq* contours;
CvSeq* hull;
cvFindContours( img, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, CvPoint(0,0) );
hull = cvConvexHull2( contours, storage, CV_CLOCKWISE, 0 );
Where img
and contours
are both valid. There is a lot more between these lines, but the FindContours portion of it has been tested to work.
This code throws exception: Error: Bad argument (Unsupported sequence type) in cvApproxPoly.
I'm told that the problem is that the flag that identifies the sequence as a polyline is not set, and I have tried the suggestion hull->flags = hull->flags | 512
but presumably the flags have changed sometime between 2008 and now, since that does not work.
So the question is: how do I use cvApproxPoly() on the results of a cvConvexHull2()? What data type should I use, and what are the proper arguments for cvApproxPoly()?