From 3a1f24e74c1cdd377c51c215276cb7a532717bba Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 27 May 2011 20:32:48 +0000 Subject: [PATCH] fixed mat.push_back(mat) (ticket #1091) --- modules/core/src/matrix.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index f3a545815..25bc91811 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -579,16 +579,20 @@ void Mat::push_back(const Mat& elems) int r = size.p[0], delta = elems.size.p[0]; if( delta == 0 ) return; - if( this != &elems ) + if( this == &elems ) { - size.p[0] = elems.size.p[0]; - bool eq = size == elems.size; - size.p[0] = r; - if( !eq ) - CV_Error(CV_StsUnmatchedSizes, ""); - if( type() != elems.type() ) - CV_Error(CV_StsUnmatchedFormats, ""); + Mat tmp = elems; + push_back(tmp); + return; } + + size.p[0] = elems.size.p[0]; + bool eq = size == elems.size; + size.p[0] = r; + if( !eq ) + CV_Error(CV_StsUnmatchedSizes, ""); + if( type() != elems.type() ) + CV_Error(CV_StsUnmatchedFormats, ""); if( isSubmatrix() || dataend + step.p[0]*delta > datalimit ) reserve( std::max(r + delta, (r*3+1)/2) );