Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8bcc2c

Browse files
authored
Merge pull request #25996 from asmorkalov:as/fillPoly_check
Fixed asserts in fillPoly
2 parents 1acf722 + 9dee2c6 commit d8bcc2c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import numpy as np
6+
import cv2 as cv
7+
8+
from tests_common import NewOpenCVTests
9+
10+
class Imgproc_Tests(NewOpenCVTests):
11+
12+
def test_python_986(self):
13+
cntls = []
14+
img = np.zeros((100,100,3), dtype=np.uint8)
15+
color = (0,0,0)
16+
cnts = np.array(cntls, dtype=np.int32).reshape((1, -1, 2))
17+
try:
18+
cv.fillPoly(img, cnts, color)
19+
assert False
20+
except:
21+
assert True

modules/imgproc/src/drawing.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,8 +2044,11 @@ void fillPoly( InputOutputArray _img, const Point** pts, const int* npts, int nc
20442044
edges.reserve( total + 1 );
20452045
for (i = 0; i < ncontours; i++)
20462046
{
2047-
std::vector<Point2l> _pts(pts[i], pts[i] + npts[i]);
2048-
CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset);
2047+
if (npts[i] > 0 && pts[i])
2048+
{
2049+
std::vector<Point2l> _pts(pts[i], pts[i] + npts[i]);
2050+
CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset);
2051+
}
20492052
}
20502053

20512054
FillEdgeCollection(img, edges, buf, line_type);
@@ -2430,7 +2433,7 @@ void cv::fillPoly(InputOutputArray img, InputArrayOfArrays pts,
24302433
for( i = 0; i < ncontours; i++ )
24312434
{
24322435
Mat p = pts.getMat(manyContours ? i : -1);
2433-
CV_Assert(p.checkVector(2, CV_32S) >= 0);
2436+
CV_Assert(p.checkVector(2, CV_32S) > 0);
24342437
ptsptr[i] = p.ptr<Point>();
24352438
npts[i] = p.rows*p.cols*p.channels()/2;
24362439
}

0 commit comments

Comments
 (0)