Skip to content

Commit b28d134

Browse files
committed
1 parent 726efee commit b28d134

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

modules/core/src/stat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,11 @@ void cv::findNonZero( InputArray _src, OutputArray _idx )
25872587
Mat src = _src.getMat();
25882588
CV_Assert( src.type() == CV_8UC1 );
25892589
int n = countNonZero(src);
2590+
if (n == 0)
2591+
{
2592+
_idx.release();
2593+
return;
2594+
}
25902595
if( _idx.kind() == _InputArray::MAT && !_idx.getMatRef().isContinuous() )
25912596
_idx.release();
25922597
_idx.create(n, 1, CV_32SC2);

modules/core/test/test_arithm.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,3 +1810,13 @@ TEST(MinMaxLoc, Mat_IntMax_Without_Mask)
18101810
ASSERT_EQ(Point(0, 0), minLoc);
18111811
ASSERT_EQ(Point(0, 0), maxLoc);
18121812
}
1813+
1814+
1815+
TEST(Core_FindNonZero, singular)
1816+
{
1817+
Mat img(10, 10, CV_8U, Scalar::all(0));
1818+
vector<Point> pts, pts2(10);
1819+
findNonZero(img, pts);
1820+
findNonZero(img, pts2);
1821+
ASSERT_TRUE(pts.empty() && pts2.empty());
1822+
}

0 commit comments

Comments
 (0)