From d2409d12c6e396cf3a882b9aa14edee13b879b27 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Fri, 24 Apr 2015 17:11:51 +0300 Subject: [PATCH] porting polylines with empty `vector` from 2.4 to master --- modules/imgproc/src/drawing.cpp | 3 +++ modules/imgproc/test/test_contours.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index 27411b247..e52312a3b 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -2229,7 +2229,10 @@ void cv::polylines(InputOutputArray _img, InputArrayOfArrays pts, { Mat p = pts.getMat(manyContours ? i : -1); if( p.total() == 0 ) + { + npts[i] = 0; continue; + } CV_Assert(p.checkVector(2, CV_32S) >= 0); ptsptr[i] = p.ptr(); npts[i] = p.rows*p.cols*p.channels()/2; diff --git a/modules/imgproc/test/test_contours.cpp b/modules/imgproc/test/test_contours.cpp index 6c5c3f0eb..b0b8c4fbb 100644 --- a/modules/imgproc/test/test_contours.cpp +++ b/modules/imgproc/test/test_contours.cpp @@ -410,4 +410,23 @@ TEST(Core_Drawing, _914) ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn); } +TEST(Core_Drawing, polylines_empty) +{ + Mat img(100, 100, CV_8UC1, Scalar(0)); + vector pts; // empty + polylines(img, pts, false, Scalar(255)); + int cnt = countNonZero(img); + ASSERT_EQ(cnt, 0); +} + +TEST(Core_Drawing, polylines) +{ + Mat img(100, 100, CV_8UC1, Scalar(0)); + vector pts; + pts.push_back(Point(0, 0)); + pts.push_back(Point(20, 0)); + polylines(img, pts, false, Scalar(255)); + int cnt = countNonZero(img); + ASSERT_EQ(cnt, 21); +} /* End of file. */