From 12383a124be9bd9a5d8d7b8a14fa99ecf2c7a0f0 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 5 Dec 2016 14:26:15 +0300 Subject: [PATCH] Disable error throwing in convexityDefects when hull is a line or point --- modules/imgproc/src/convhull.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/convhull.cpp b/modules/imgproc/src/convhull.cpp index f7e7c2291d..1f8ef7b44b 100644 --- a/modules/imgproc/src/convhull.cpp +++ b/modules/imgproc/src/convhull.cpp @@ -280,11 +280,16 @@ void convexityDefects( InputArray _points, InputArray _hull, OutputArray _defect Mat hull = _hull.getMat(); int hpoints = hull.checkVector(1, CV_32S); - CV_Assert( hpoints > 2 ); + CV_Assert( hpoints > 0 ); const Point* ptr = points.ptr(); const int* hptr = hull.ptr(); std::vector defects; + if ( hpoints < 3 ) //if hull consists of one or two points, contour is always convex + { + _defects.release(); + return; + } // 1. recognize co-orientation of the contour and its hull bool rev_orientation = ((hptr[1] > hptr[0]) + (hptr[2] > hptr[1]) + (hptr[0] > hptr[2])) != 2;