From 0d7a37c1e79cc15d95634d10e53cddfa6019dede Mon Sep 17 00:00:00 2001 From: Maria Dimashova Date: Thu, 21 Jul 2011 09:38:25 +0000 Subject: [PATCH] added an ability to make push_back to the empty matrix --- modules/core/include/opencv2/core/mat.hpp | 7 ++++++- modules/core/src/matrix.cpp | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index a69673820..a7b2041eb 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -675,7 +675,12 @@ template inline Mat::operator Matx<_Tp, m, n>() cons template inline void Mat::push_back(const _Tp& elem) { - CV_Assert(DataType<_Tp>::type == type() && cols == 1 + if( !data ) + { + *this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone(); + return; + } + CV_Assert(DataType<_Tp>::type == type() && cols == 1 /* && dims == 2 (cols == 1 implies dims == 2) */); uchar* tmp = dataend + step[0]; if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 4654a78f4..e55b0031a 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -585,6 +585,11 @@ void Mat::push_back(const Mat& elems) push_back(tmp); return; } + if( !data ) + { + *this = elems.clone(); + return; + } size.p[0] = elems.size.p[0]; bool eq = size == elems.size;