From 30a5a9ed34021524ba2510e1aa4c0022ce67f2ff Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 26 Jun 2015 13:35:27 +0300 Subject: [PATCH] test vector processing --- modules/core/test/test_mat.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 74fc75d..07d4523 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1318,3 +1318,82 @@ TEST(Core_SparseMat, footprint) ASSERT_LE((int)m.hdr->nodeSize, 32); ASSERT_LE(dataSize1, threshold); } + + +TEST(Core_Mat_vector, OutputArray_create_getMat) +{ + cv::Mat_ src_base(5, 1); + std::vector dst8; + + src_base << 1, 2, 3, 4, 5; + + Mat src(src_base); + OutputArray _dst(dst8); + { + _dst.create(src.rows, src.cols, src.type()); + Mat dst = _dst.getMat(); + EXPECT_EQ(src.dims, dst.dims); + EXPECT_EQ(src.cols, dst.cols); + EXPECT_EQ(src.rows, dst.rows); + } +} + +TEST(Core_Mat_vector, copyTo_roi_column) +{ + cv::Mat_ src_base(5, 2); + std::vector dst1; + + src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; + + Mat src_full(src_base); + Mat src(src_full.col(0)); + OutputArray _dst(dst1); + { + _dst.create(src.rows, src.cols, src.type()); + Mat dst = _dst.getMat(); + EXPECT_EQ(src.dims, dst.dims); + EXPECT_EQ(src.cols, dst.cols); + EXPECT_EQ(src.rows, dst.rows); + } + + std::vector dst2; + src.copyTo(dst2); + std::cout << "src = " << src << std::endl; + std::cout << "dst = " << Mat(dst2) << std::endl; + EXPECT_EQ((size_t)5, dst2.size()); + EXPECT_EQ(1, (int)dst2[0]); + EXPECT_EQ(3, (int)dst2[1]); + EXPECT_EQ(5, (int)dst2[2]); + EXPECT_EQ(7, (int)dst2[3]); + EXPECT_EQ(9, (int)dst2[4]); +} + +TEST(Core_Mat_vector, copyTo_roi_row) +{ + cv::Mat_ src_base(2, 5); + std::vector dst1; + + src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; + + Mat src_full(src_base); + Mat src(src_full.row(0)); + OutputArray _dst(dst1); + { + _dst.create(src.rows, src.cols, src.type()); + Mat dst = _dst.getMat(); + EXPECT_EQ(src.dims, dst.dims); + EXPECT_EQ(src.cols, dst.cols); + EXPECT_EQ(src.rows, dst.rows); + } + + std::vector dst2; + src.copyTo(dst2); + std::cout << "src = " << src << std::endl; + std::cout << "dst = " << Mat(dst2) << std::endl; + EXPECT_EQ((size_t)5, dst2.size()); + EXPECT_EQ(1, (int)dst2[0]); + EXPECT_EQ(2, (int)dst2[1]); + EXPECT_EQ(3, (int)dst2[2]); + EXPECT_EQ(4, (int)dst2[3]); + EXPECT_EQ(5, (int)dst2[4]); +} -- 2.7.4