fixed http://code.opencv.org/issues/3828, added test. thanks to berak for the patch

pull/3987/head
Vadim Pisarevsky 10 years ago
parent 0746ec7035
commit d8f360316d
  1. 5
      modules/core/src/stat.cpp
  2. 10
      modules/core/test/test_arithm.cpp

@ -3826,6 +3826,11 @@ void cv::findNonZero( InputArray _src, OutputArray _idx )
Mat src = _src.getMat();
CV_Assert( src.type() == CV_8UC1 );
int n = countNonZero(src);
if( n == 0 )
{
_idx.release();
return;
}
if( _idx.kind() == _InputArray::MAT && !_idx.getMatRef().isContinuous() )
_idx.release();
_idx.create(n, 1, CV_32SC2);

@ -1791,3 +1791,13 @@ INSTANTIATE_TEST_CASE_P(Arithm, SubtractOutputMatNotEmpty, testing::Combine(
testing::Values(perf::MatType(CV_8UC1), CV_8UC3, CV_8UC4, CV_16SC1, CV_16SC3),
testing::Values(-1, CV_16S, CV_32S, CV_32F),
testing::Bool()));
TEST(Core_FindNonZero, singular)
{
Mat img(10, 10, CV_8U, Scalar::all(0));
vector<Point> pts, pts2(10);
findNonZero(img, pts);
findNonZero(img, pts2);
ASSERT_TRUE(pts.empty() && pts2.empty());
}

Loading…
Cancel
Save