Merge pull request #11634 from vpisarev:empty_mat_with_types_2

fixes handling of empty matrices in some functions (#11634)

* a part of PR #11416 by Yuki Takehara

* moved the empty mat check in Mat::copyTo()

* fixed some test failures
pull/11465/merge
Vadim Pisarevsky 7 years ago committed by Alexander Alekhin
parent da75e463a8
commit 7d19bd6c19
  1. 2
      modules/calib3d/test/test_stereomatching.cpp
  2. 2
      modules/core/include/opencv2/core/mat.inl.hpp
  3. 6
      modules/core/src/arithm.cpp
  4. 6
      modules/core/src/convert.cpp
  5. 11
      modules/core/src/copy.cpp
  6. 6
      modules/features2d/src/agast.cpp
  7. 6
      modules/features2d/src/fast.cpp
  8. 6
      modules/features2d/src/gftt.cpp
  9. 8
      modules/imgproc/src/hough.cpp

@ -556,7 +556,7 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca
assert( fs.isOpened() );
assert( trueLeftDisp.type() == CV_32FC1 );
assert( trueRightDisp.empty() || trueRightDisp.type() == CV_32FC1 );
assert( leftDisp.type() == CV_32FC1 && rightDisp.type() == CV_32FC1 );
assert( leftDisp.type() == CV_32FC1 && (rightDisp.empty() || rightDisp.type() == CV_32FC1) );
// get masks for unknown ground truth disparity values
Mat leftUnknMask, rightUnknMask;

@ -1673,7 +1673,7 @@ Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
{
return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0));
}
CV_DbgAssert(DataType<_Tp>::channels == m.channels());
CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty());
m.convertTo(*this, type());
return *this;
}

@ -1233,6 +1233,12 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
CV_Assert( op == CMP_LT || op == CMP_LE || op == CMP_EQ ||
op == CMP_NE || op == CMP_GE || op == CMP_GT );
if(_src1.empty() && _src2.empty())
{
_dst.release();
return;
}
bool haveScalar = false;
if ((_src1.isMatx() + _src2.isMatx()) == 1

@ -1304,6 +1304,12 @@ void cv::Mat::convertTo(OutputArray _dst, int _type, double alpha, double beta)
{
CV_INSTRUMENT_REGION()
if( empty() )
{
_dst.release();
return;
}
bool noScale = fabs(alpha-1) < DBL_EPSILON && fabs(beta) < DBL_EPSILON;
if( _type < 0 )

@ -246,13 +246,14 @@ void Mat::copyTo( OutputArray _dst ) const
return;
}
if( empty() )
{
_dst.release();
return;
}
if( _dst.isUMat() )
{
if( empty() )
{
_dst.release();
return;
}
_dst.create( dims, size.p, type() );
UMat dst = _dst.getUMat();
CV_Assert(dst.u != NULL);

@ -7952,6 +7952,12 @@ public:
{
CV_INSTRUMENT_REGION()
if(_image.empty())
{
keypoints.clear();
return;
}
Mat mask = _mask.getMat(), grayImage;
UMat ugrayImage;
_InputArray gray = _image;

@ -526,6 +526,12 @@ public:
{
CV_INSTRUMENT_REGION()
if(_image.empty())
{
keypoints.clear();
return;
}
Mat mask = _mask.getMat(), grayImage;
UMat ugrayImage;
_InputArray gray = _image;

@ -80,6 +80,12 @@ public:
{
CV_INSTRUMENT_REGION()
if(_image.empty())
{
keypoints.clear();
return;
}
std::vector<Point2f> corners;
if (_image.isUMat())

@ -803,7 +803,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub
int total_points = counters.getMat(ACCESS_READ).at<int>(0, 0);
if (total_points <= 0)
{
_lines.assign(UMat(0,0,CV_32FC2));
_lines.release();
return true;
}
@ -831,7 +831,7 @@ static bool ocl_HoughLines(InputArray _src, OutputArray _lines, double rho, doub
if (total_lines > 0)
_lines.assign(lines.rowRange(Range(0, total_lines)));
else
_lines.assign(UMat(0,0,CV_32FC2));
_lines.release();
return true;
}
@ -857,7 +857,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou
int total_points = counters.getMat(ACCESS_READ).at<int>(0, 0);
if (total_points <= 0)
{
_lines.assign(UMat(0,0,CV_32SC4));
_lines.release();
return true;
}
@ -885,7 +885,7 @@ static bool ocl_HoughLinesP(InputArray _src, OutputArray _lines, double rho, dou
if (total_lines > 0)
_lines.assign(lines.rowRange(Range(0, total_lines)));
else
_lines.assign(UMat(0,0,CV_32SC4));
_lines.release();
return true;
}

Loading…
Cancel
Save