From 71aee662bd89be24b858f18c3d7abfecacc69c2e Mon Sep 17 00:00:00 2001 From: Lee Jaehwan Date: Fri, 4 Jan 2019 21:10:50 +0900 Subject: [PATCH] Merge pull request #13544 from eightco:bugfix Fix a bug in cv :: merge when array of 3-channel mat is input (#13544) * Mat merge function bug fix - Bug fix of merge function of 3-channel vector of 3 or 4 matrices * Add Core_merge test for opencv#13544 * fixups --- modules/core/src/merge.cpp | 2 +- modules/core/test/test_mat.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/core/src/merge.cpp b/modules/core/src/merge.cpp index b460d21..0aeaa82 100644 --- a/modules/core/src/merge.cpp +++ b/modules/core/src/merge.cpp @@ -305,7 +305,7 @@ void cv::merge(const Mat* mv, size_t n, OutputArray _dst) return; } - CV_IPP_RUN_FAST(ipp_merge(mv, dst, (int)n)); + CV_IPP_RUN(allch1, ipp_merge(mv, dst, (int)n)); if( !allch1 ) { diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index f585c4f..f69140b 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1888,6 +1888,29 @@ TEST(Core_Split, crash_12171) EXPECT_EQ(2, dst2.ptr(1)[1]); } +TEST(Core_Merge, bug_13544) +{ + Mat src1(2, 2, CV_8UC3, Scalar::all(1)); + Mat src2(2, 2, CV_8UC3, Scalar::all(2)); + Mat src3(2, 2, CV_8UC3, Scalar::all(3)); + Mat src_arr[] = { src1, src2, src3 }; + Mat dst; + merge(src_arr, 3, dst); + ASSERT_EQ(9, dst.channels()); // Avoid memory access out of buffer + EXPECT_EQ(3, (int)dst.ptr(0)[6]); + EXPECT_EQ(3, (int)dst.ptr(0)[7]); + EXPECT_EQ(3, (int)dst.ptr(0)[8]); + EXPECT_EQ(1, (int)dst.ptr(1)[0]); + EXPECT_EQ(1, (int)dst.ptr(1)[1]); + EXPECT_EQ(1, (int)dst.ptr(1)[2]); + EXPECT_EQ(2, (int)dst.ptr(1)[3]); + EXPECT_EQ(2, (int)dst.ptr(1)[4]); + EXPECT_EQ(2, (int)dst.ptr(1)[5]); + EXPECT_EQ(3, (int)dst.ptr(1)[6]); + EXPECT_EQ(3, (int)dst.ptr(1)[7]); + EXPECT_EQ(3, (int)dst.ptr(1)[8]); +} + struct CustomType // like cv::Keypoint { Point2f pt; -- 2.7.4