Skip to content

Commit 7a3b5b3

Browse files
committed
Merge pull request opencv#7790 from sovrasov:convexity_defects_enable_small_hulls
2 parents fbf2383 + 12383a1 commit 7a3b5b3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

modules/imgproc/src/convhull.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,16 @@ void convexityDefects( InputArray _points, InputArray _hull, OutputArray _defect
280280

281281
Mat hull = _hull.getMat();
282282
int hpoints = hull.checkVector(1, CV_32S);
283-
CV_Assert( hpoints > 2 );
283+
CV_Assert( hpoints > 0 );
284284

285285
const Point* ptr = points.ptr<Point>();
286286
const int* hptr = hull.ptr<int>();
287287
std::vector<Vec4i> defects;
288+
if ( hpoints < 3 ) //if hull consists of one or two points, contour is always convex
289+
{
290+
_defects.release();
291+
return;
292+
}
288293

289294
// 1. recognize co-orientation of the contour and its hull
290295
bool rev_orientation = ((hptr[1] > hptr[0]) + (hptr[2] > hptr[1]) + (hptr[0] > hptr[2])) != 2;

0 commit comments

Comments
 (0)