From 9dee2c6e6735230fcea83c3db7f5656df834ae4f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 6 Aug 2024 10:40:45 +0300 Subject: [PATCH] Fixed asserts in fillPoly. --- .../imgproc/misc/python/test/test_imgproc.py | 21 +++++++++++++++++++ modules/imgproc/src/drawing.cpp | 9 +++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 modules/imgproc/misc/python/test/test_imgproc.py diff --git a/modules/imgproc/misc/python/test/test_imgproc.py b/modules/imgproc/misc/python/test/test_imgproc.py new file mode 100644 index 0000000000..9979b0c301 --- /dev/null +++ b/modules/imgproc/misc/python/test/test_imgproc.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import numpy as np +import cv2 as cv + +from tests_common import NewOpenCVTests + +class Imgproc_Tests(NewOpenCVTests): + + def test_python_986(self): + cntls = [] + img = np.zeros((100,100,3), dtype=np.uint8) + color = (0,0,0) + cnts = np.array(cntls, dtype=np.int32).reshape((1, -1, 2)) + try: + cv.fillPoly(img, cnts, color) + assert False + except: + assert True diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index 4d0f26f7a0..394a6d6059 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -2044,8 +2044,11 @@ void fillPoly( InputOutputArray _img, const Point** pts, const int* npts, int nc edges.reserve( total + 1 ); for (i = 0; i < ncontours; i++) { - std::vector _pts(pts[i], pts[i] + npts[i]); - CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset); + if (npts[i] > 0 && pts[i]) + { + std::vector _pts(pts[i], pts[i] + npts[i]); + CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset); + } } FillEdgeCollection(img, edges, buf, line_type); @@ -2430,7 +2433,7 @@ void cv::fillPoly(InputOutputArray img, InputArrayOfArrays pts, for( i = 0; i < ncontours; i++ ) { Mat p = pts.getMat(manyContours ? i : -1); - CV_Assert(p.checkVector(2, CV_32S) >= 0); + CV_Assert(p.checkVector(2, CV_32S) > 0); ptsptr[i] = p.ptr(); npts[i] = p.rows*p.cols*p.channels()/2; }