mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
Merge pull request #16858 from alalek:core_fix_empty_iterator_begin_end
This commit is contained in:
commit
183e4d50ed
@ -1304,6 +1304,8 @@ const _Tp& Mat::at(const Vec<int, n>& idx) const
|
||||
template<typename _Tp> inline
|
||||
MatConstIterator_<_Tp> Mat::begin() const
|
||||
{
|
||||
if (empty())
|
||||
return MatConstIterator_<_Tp>();
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
|
||||
}
|
||||
@ -1311,6 +1313,8 @@ MatConstIterator_<_Tp> Mat::begin() const
|
||||
template<typename _Tp> inline
|
||||
MatConstIterator_<_Tp> Mat::end() const
|
||||
{
|
||||
if (empty())
|
||||
return MatConstIterator_<_Tp>();
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this);
|
||||
it += total();
|
||||
@ -1320,6 +1324,8 @@ MatConstIterator_<_Tp> Mat::end() const
|
||||
template<typename _Tp> inline
|
||||
MatIterator_<_Tp> Mat::begin()
|
||||
{
|
||||
if (empty())
|
||||
return MatIterator_<_Tp>();
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
return MatIterator_<_Tp>((Mat_<_Tp>*)this);
|
||||
}
|
||||
@ -1327,6 +1333,8 @@ MatIterator_<_Tp> Mat::begin()
|
||||
template<typename _Tp> inline
|
||||
MatIterator_<_Tp> Mat::end()
|
||||
{
|
||||
if (empty())
|
||||
return MatIterator_<_Tp>();
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
MatIterator_<_Tp> it((Mat_<_Tp>*)this);
|
||||
it += total();
|
||||
@ -2690,6 +2698,7 @@ MatConstIterator::MatConstIterator(const Mat* _m)
|
||||
{
|
||||
if( m && m->isContinuous() )
|
||||
{
|
||||
CV_Assert(!m->empty());
|
||||
sliceStart = m->ptr();
|
||||
sliceEnd = sliceStart + m->total()*elemSize;
|
||||
}
|
||||
@ -2703,6 +2712,7 @@ MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col)
|
||||
CV_Assert(m && m->dims <= 2);
|
||||
if( m->isContinuous() )
|
||||
{
|
||||
CV_Assert(!m->empty());
|
||||
sliceStart = m->ptr();
|
||||
sliceEnd = sliceStart + m->total()*elemSize;
|
||||
}
|
||||
@ -2717,6 +2727,7 @@ MatConstIterator::MatConstIterator(const Mat* _m, Point _pt)
|
||||
CV_Assert(m && m->dims <= 2);
|
||||
if( m->isContinuous() )
|
||||
{
|
||||
CV_Assert(!m->empty());
|
||||
sliceStart = m->ptr();
|
||||
sliceEnd = sliceStart + m->total()*elemSize;
|
||||
}
|
||||
|
@ -2082,4 +2082,12 @@ TEST(Mat, regression_12943) // memory usage: ~4.5 Gb
|
||||
cv::flip(src, dst, 0);
|
||||
}
|
||||
|
||||
TEST(Mat, empty_iterator_16855)
|
||||
{
|
||||
cv::Mat m;
|
||||
EXPECT_NO_THROW(m.begin<uchar>());
|
||||
EXPECT_NO_THROW(m.end<uchar>());
|
||||
EXPECT_TRUE(m.begin<uchar>() == m.end<uchar>());
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user