From 5f9e295adf457e16a26277c5ef1dd42aea5c27b3 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 16 May 2012 15:11:17 +0000 Subject: [PATCH] Added test and workaround for #1942 --- modules/core/src/matrix.cpp | 10 +++++++++- modules/core/test/test_mat.cpp | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 670388d74..845bd8976 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2897,8 +2897,16 @@ cvKMeans2( const CvArr* _samples, int cluster_count, CvArr* _labels, namespace cv { -Mat Mat::reshape(int, int, const int*) const +Mat Mat::reshape(int _cn, int _newndims, const int* _newsz) const { + if(_newndims == dims) + { + if(_newsz == 0) + return reshape(_cn); + if(_newndims == 2) + return reshape(_cn, _newsz[0]); + } + CV_Error(CV_StsNotImplemented, ""); // TBD return Mat(); diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 346accdce..f588ae4a5 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -861,3 +861,14 @@ TEST(Core_IOArray, submat_create) EXPECT_THROW( OutputArray_create1(A.row(0)), cv::Exception ); EXPECT_THROW( OutputArray_create2(A.row(0)), cv::Exception ); } + +TEST(Core_Mat, reshape_1942) +{ + cv::Mat A = (cv::Mat_(2,3) << 3.4884074, 1.4159607, 0.78737736, 2.3456569, -0.88010466, 0.3009364); + int cn = 0; + ASSERT_NO_THROW( + cv::Mat_ M = A.reshape(3); + cn = M.channels(); + ); + ASSERT_EQ(1, cn); +} \ No newline at end of file