Index: H:/OpenCVWorkspace/OpenCV2.2_Learn/include/opencv2/imgproc/imgproc.hpp =================================================================== --- H:/OpenCVWorkspace/OpenCV2.2_Learn/include/opencv2/imgproc/imgproc.hpp (revision 30) +++ H:/OpenCVWorkspace/OpenCV2.2_Learn/include/opencv2/imgproc/imgproc.hpp (revision 31) @@ -828,6 +828,8 @@ //! returns true iff the contour is convex. Does not support contours with self-intersection CV_EXPORTS_W bool isContourConvex( const Mat& contour ); +CV_EXPORTS_W void ConvexityDefects( const Mat& points, const vector& hull, vector &defects ); + //! fits ellipse to the set of 2D points CV_EXPORTS_W RotatedRect fitEllipse( const Mat& points ); Index: H:/OpenCVWorkspace/OpenCV2.2_Learn/modules/imgproc/src/contours.cpp =================================================================== --- H:/OpenCVWorkspace/OpenCV2.2_Learn/modules/imgproc/src/contours.cpp (revision 30) +++ H:/OpenCVWorkspace/OpenCV2.2_Learn/modules/imgproc/src/contours.cpp (revision 31) @@ -1744,6 +1744,24 @@ return cvCheckContourConvexity(&c) > 0; } +void cv::ConvexityDefects( const Mat& points, const vector& hull, vector &defects ) +{ + int nelems = points.checkVector(2, CV_32S); + int nhelems = (int)hull.size(); + if (nelems < nhelems) + { + defects.clear(); + return; + } + + // convert to CvMat (C API) + CvMat _points = Mat(points), _hull=Mat(hull); + // allocate storage for the defects + MemStorage storage(cvCreateMemStorage()); + Seq defectSeq( cvConvexityDefects(&_points, &_hull, storage) ); + defectSeq.copyTo(defects); +} + cv::RotatedRect cv::fitEllipse( const Mat& points ) { CV_Assert(points.checkVector(2) >= 0 &&