diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index c6cfb78f77..4e86be7196 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -2482,8 +2482,8 @@ public: UMat(const UMat& m, const Range* ranges); UMat(const UMat& m, const std::vector& ranges); - // FIXIT copyData=false is not implemented, drop this in favor of cv::Mat (OpenCV 5.0) - //! builds matrix from std::vector with or without copying the data + //! builds matrix from std::vector. The data is always copied. The copyData + //! parameter is deprecated and will be removed in OpenCV 5.0. template explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); //! destructor - calls release() diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 94353a0678..8f904559d9 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -3254,18 +3254,13 @@ const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) template inline UMat::UMat(const std::vector<_Tp>& vec, bool copyData) -: flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), -cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) + : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), + cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) { + CV_UNUSED(copyData); // parameter kept for backward compatibility if(vec.empty()) return; - if( !copyData ) - { - // !!!TODO!!! - CV_Error(Error::StsNotImplemented, ""); - } - else - Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); } inline diff --git a/modules/core/test/test_umat.cpp b/modules/core/test/test_umat.cpp index a89972762a..34e6d2be75 100644 --- a/modules/core/test/test_umat.cpp +++ b/modules/core/test/test_umat.cpp @@ -919,6 +919,28 @@ TEST(Core_UMat, getUMat) EXPECT_EQ(0., err); } } +#include "test_precomp.hpp" + +TEST(Core_UMat, construct_from_vector) +{ + std::vector src = {1, 2, 3, 4}; + UMat um(src); // copyData parameter is deprecated and ignored + + src[0] = 100; // modify source to ensure data was copied + + Mat result; + um.copyTo(result); + + ASSERT_EQ(4, result.rows); + ASSERT_EQ(1, result.cols); + ASSERT_EQ(CV_32S, result.type()); + EXPECT_EQ(1, result.at(0)); + EXPECT_EQ(2, result.at(1)); + EXPECT_EQ(3, result.at(2)); + EXPECT_EQ(4, result.at(3)); +} + + TEST(UMat, Sync) { @@ -1452,4 +1474,6 @@ TEST(UMat, exceptions_refcounts_issue_20594) umat1.u->handle = original_handle; } +#include "test_precomp.hpp" + } } // namespace opencv_test::ocl