diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 08c5501e4e..02160ecd61 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -839,9 +839,9 @@ void Mat::push_back(const Mat& elems) bool eq = size == elems.size; size.p[0] = r; if( !eq ) - CV_Error(CV_StsUnmatchedSizes, ""); + CV_Error(CV_StsUnmatchedSizes, "Pushed vector length is not equal to matrix row length"); if( type() != elems.type() ) - CV_Error(CV_StsUnmatchedFormats, ""); + CV_Error(CV_StsUnmatchedFormats, "Pushed vector type is not the same as matrix type"); if( isSubmatrix() || dataend + step.p[0]*delta > datalimit ) reserve( std::max(r + delta, (r*3+1)/2) ); diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 9aeb02ed39..95e4c055d7 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1520,3 +1520,21 @@ TEST(Reduce, regression_should_fail_bug_4594) EXPECT_NO_THROW(cv::reduce(src, dst, 0, CV_REDUCE_SUM, CV_32S)); EXPECT_NO_THROW(cv::reduce(src, dst, 0, CV_REDUCE_AVG, CV_32S)); } + +TEST(Mat, push_back_vector) +{ + cv::Mat result(1, 5, CV_32FC1); + + std::vector vec1(result.cols + 1); + std::vector vec2(result.cols); + + EXPECT_THROW(result.push_back(vec1), cv::Exception); + EXPECT_THROW(result.push_back(vec2), cv::Exception); + + vec1.resize(result.cols); + + for (int i = 0; i < 5; ++i) + result.push_back(cv::Mat(vec1).reshape(1, 1)); + + ASSERT_EQ(6, result.rows); +}