Skip to content

Commit b59df66

Browse files
committed
Merge pull request opencv#8698 from cdcseacave:fix_Mat_release
2 parents c3762fb + 2c2b140 commit b59df66

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

modules/core/include/opencv2/core/mat.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,8 @@ template<typename _Tp> class Mat_ : public Mat
21852185
void create(Size _size);
21862186
//! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
21872187
void create(int _ndims, const int* _sizes);
2188+
//! equivalent to Mat::release()
2189+
void release();
21882190
//! cross-product
21892191
Mat_ cross(const Mat_& m) const;
21902192
//! data type conversion
@@ -2676,11 +2678,11 @@ class CV_EXPORTS SparseMat
26762678
/*!
26772679
@param [out] m - output matrix; if it does not have a proper size or type before the operation,
26782680
it is reallocated
2679-
@param [in] rtype desired output matrix type or, rather, the depth since the number of channels
2681+
@param [in] rtype - desired output matrix type or, rather, the depth since the number of channels
26802682
are the same as the input has; if rtype is negative, the output matrix will have the
26812683
same type as the input.
2682-
@param [in] alpha optional scale factor
2683-
@param [in] beta optional delta added to the scaled values
2684+
@param [in] alpha - optional scale factor
2685+
@param [in] beta - optional delta added to the scaled values
26842686
*/
26852687
void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
26862688

modules/core/include/opencv2/core/mat.inl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,15 @@ void Mat_<_Tp>::create(int _dims, const int* _sz)
16251625
Mat::create(_dims, _sz, DataType<_Tp>::type);
16261626
}
16271627

1628+
template<typename _Tp> inline
1629+
void Mat_<_Tp>::release()
1630+
{
1631+
Mat::release();
1632+
#ifdef _DEBUG
1633+
flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type;
1634+
#endif
1635+
}
1636+
16281637
template<typename _Tp> inline
16291638
Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const
16301639
{

modules/core/test/test_mat.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,4 +1725,12 @@ TEST(Core_Mat_array, SplitMerge)
17251725
EXPECT_EQ(0, countNonZero(diff));
17261726
}
17271727
}
1728-
#endif
1728+
#endif
1729+
1730+
TEST(Mat, regression_8680)
1731+
{
1732+
Mat_<Point2i> mat(3,1);
1733+
ASSERT_EQ(mat.channels(), 2);
1734+
mat.release();
1735+
ASSERT_EQ(mat.channels(), 2);
1736+
}

0 commit comments

Comments
 (0)