mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
convex hull converted to C++; other 2 functions in convhull.cpp are yet to be finished.
This commit is contained in:
@@ -1813,77 +1813,6 @@ double cv::matchShapes( InputArray _contour1,
|
||||
}
|
||||
|
||||
|
||||
void cv::convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool returnPoints )
|
||||
{
|
||||
Mat points = _points.getMat();
|
||||
int nelems = points.checkVector(2), depth = points.depth();
|
||||
CV_Assert(nelems >= 0 && (depth == CV_32F || depth == CV_32S));
|
||||
|
||||
if( nelems == 0 )
|
||||
{
|
||||
_hull.release();
|
||||
return;
|
||||
}
|
||||
|
||||
returnPoints = !_hull.fixedType() ? returnPoints : _hull.type() != CV_32S;
|
||||
Mat hull(nelems, 1, returnPoints ? CV_MAKETYPE(depth, 2) : CV_32S);
|
||||
CvMat _cpoints = points, _chull = hull;
|
||||
cvConvexHull2(&_cpoints, &_chull, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, returnPoints);
|
||||
_hull.create(_chull.rows, 1, hull.type(), -1, true);
|
||||
Mat dhull = _hull.getMat(), shull(dhull.size(), dhull.type(), hull.data);
|
||||
shull.copyTo(dhull);
|
||||
}
|
||||
|
||||
|
||||
void cv::convexityDefects( InputArray _points, InputArray _hull, OutputArray _defects )
|
||||
{
|
||||
Mat points = _points.getMat();
|
||||
int ptnum = points.checkVector(2, CV_32S);
|
||||
CV_Assert( ptnum > 3 );
|
||||
Mat hull = _hull.getMat();
|
||||
CV_Assert( hull.checkVector(1, CV_32S) > 2 );
|
||||
Ptr<CvMemStorage> storage = cvCreateMemStorage();
|
||||
|
||||
CvMat c_points = points, c_hull = hull;
|
||||
CvSeq* seq = cvConvexityDefects(&c_points, &c_hull, storage);
|
||||
int i, n = seq->total;
|
||||
|
||||
if( n == 0 )
|
||||
{
|
||||
_defects.release();
|
||||
return;
|
||||
}
|
||||
|
||||
_defects.create(n, 1, CV_32SC4);
|
||||
Mat defects = _defects.getMat();
|
||||
|
||||
SeqIterator<CvConvexityDefect> it = Seq<CvConvexityDefect>(seq).begin();
|
||||
CvPoint* ptorg = (CvPoint*)points.data;
|
||||
|
||||
for( i = 0; i < n; i++, ++it )
|
||||
{
|
||||
CvConvexityDefect& d = *it;
|
||||
int idx0 = (int)(d.start - ptorg);
|
||||
int idx1 = (int)(d.end - ptorg);
|
||||
int idx2 = (int)(d.depth_point - ptorg);
|
||||
CV_Assert( 0 <= idx0 && idx0 < ptnum );
|
||||
CV_Assert( 0 <= idx1 && idx1 < ptnum );
|
||||
CV_Assert( 0 <= idx2 && idx2 < ptnum );
|
||||
CV_Assert( d.depth >= 0 );
|
||||
int idepth = cvRound(d.depth*256);
|
||||
defects.at<Vec4i>(i) = Vec4i(idx0, idx1, idx2, idepth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool cv::isContourConvex( InputArray _contour )
|
||||
{
|
||||
Mat contour = _contour.getMat();
|
||||
CV_Assert(contour.checkVector(2) >= 0 &&
|
||||
(contour.depth() == CV_32F || contour.depth() == CV_32S));
|
||||
CvMat c = Mat(contour);
|
||||
return cvCheckContourConvexity(&c) > 0;
|
||||
}
|
||||
|
||||
cv::RotatedRect cv::fitEllipse( InputArray _points )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user