opencv/modules/core/test
Kavyansh Tyagi 7ca36d9c50
Merge pull request #27408 from KAVYANSHTYAGI:Umat-vector-contructor
Deprecate copyData Parameter in UMat Construction from std::vector and Always Copy Data #27408

Overview

This PR simplifies and modernizes the construction of cv::UMat from std::vector by removing the legacy copyData parameter, always copying the data, and ensuring clearer, safer semantics. This brings UMat in line with current best practices and paves the way for the upcoming OpenCV 5.x series.

What Changed?

1. Header Documentation Update

    Removed confusing or obsolete documentation about copyData and clarified the behavior:

        Old: builds matrix from std::vector with or without copying the data

        New: builds matrix from std::vector. The data is always copied. The copyData parameter is deprecated and will be removed in OpenCV 5.0.

2. Implementation Update

    In UMat::UMat(const std::vector<_Tp>& vec, bool copyData), the copyData parameter:

        Is now ignored and marked as deprecated.

        Marked with CV_UNUSED(copyData) for backward compatibility and to avoid warnings.

    The constructor always copies the data from the input vector, regardless of the value of copyData.

    All branching logic around copyData has been removed. Any code for "not copying" was not implemented and is now dropped.

    This guarantees data safety and predictable behavior.

3. Test Added

    A new test construct_from_vector in test_umat_from_vector.cpp:

        Verifies that UMat copies the vector data, not referencing it.

        Modifies the source vector after construction to confirm that the UMat is unaffected (proving copy, not reference).

        Checks matrix shape, type, and content to ensure correctness.

Why This Change?

1. Safety and Predictability

    Always copying avoids dangling references and hard-to-debug lifetime issues with stack/heap-allocated vectors.

    Removes an undocumented, unimplemented branch (copyData=false).

2. Backward Compatibility

    The constructor signature remains for now, but the copyData parameter is marked as deprecated and ignored.

    Codebases that pass the parameter will still compile and run as before (but always copy).

3. API Clarity and Maintenance

    Documentation now matches the real implementation.

    No misleading expectations about zero-copy.

    Code is cleaner, future-proof, and easier to maintain.

4. Preparation for OpenCV 5.0

    The copyData parameter is deprecated and will be removed in OpenCV 5.x.

    Prepares users and downstream libraries for the planned change.



How This Helps OpenCV Users and Developers

    Guarantees data safety and makes behavior explicit.

    Removes legacy/ambiguous code.

    Provides a clear path to OpenCV 5.x.

    Minimizes future migration pain.

    Ensures all users see the same, reliable behavior (copy semantics).


Refer:#27409
2025-06-09 16:02:38 +03:00
..
ocl core(ocl): fix POWN OpenCL implementation 2025-05-01 20:57:23 +00:00
ref_reduce_arg.impl.hpp test: fix technical issue with min_element in reduce tests 2024-11-26 21:55:41 +03:00
test_allocator.cpp Set and check allocator pointer for all cv::Mat instances. 2024-08-05 10:07:14 +03:00
test_arithm.cpp fix exp, log | enable ui for log | strengthen test 2025-03-07 17:11:26 +00:00
test_async.cpp Merge pull request #23736 from seanm:c++11-simplifications 2024-01-19 16:53:08 +03:00
test_concatenation.cpp Added more strict checks for empty inputs to compare, meanStdDev and RNG::fill 2018-07-26 18:06:38 +03:00
test_conjugate_gradient.cpp ts: refactor OpenCV tests 2018-02-03 19:39:47 +00:00
test_countnonzero.cpp Add missing std namespace qualifiers 2023-09-06 13:46:39 +03:00
test_cuda.cpp add cuda::Stream constructor with cuda flags 2021-01-28 16:14:01 +01:00
test_downhill_simplex.cpp Misc. modules/ typos 2018-02-12 07:09:43 -05:00
test_ds.cpp Merge remote-tracking branch 'upstream/3.4' into merge-3.4 2021-12-03 12:32:49 +00:00
test_dxt.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
test_eigen.cpp Fix modules/ typos 2019-08-16 17:34:29 +03:00
test_hal_core.cpp fix exp, log | enable ui for log | strengthen test 2025-03-07 17:11:26 +00:00
test_hasnonzero.cpp Merge pull request #22947 from chacha21:hasNonZero 2023-06-09 13:37:20 +03:00
test_intrin128.simd.hpp Merge pull request #22179 from hanliutong:new-rvv 2022-07-19 20:02:00 +03:00
test_intrin256.simd.hpp core(test): intrinsic tests for all dispatched CPU optimizations 2018-08-01 13:50:42 +03:00
test_intrin512.simd.hpp Merge pull request #14210 from terfendail:wui_512 2019-06-03 18:05:35 +03:00
test_intrin_emulator.cpp Merge pull request #16236 from alalek:fix_core_simd_emulator 2020-01-10 21:31:02 +03:00
test_intrin_utils.hpp Merge pull request #27343 from fengyuentau:4x/build/fix_more_warnings 2025-05-21 16:12:09 +03:00
test_intrin.cpp core: fix F16C compilation check 2020-11-17 12:22:49 +00:00
test_io.cpp Refactor test for FileStorage Base64 2025-02-09 01:38:14 +03:00
test_logger_replace.cpp Merge pull request #27154 from kinchungwong:logging_callback_simple_c 2025-03-30 16:17:07 +03:00
test_logtagconfigparser.cpp Merge pull request #13909 from kinchungwong:logging_20190220 2019-04-22 00:01:10 +03:00
test_logtagmanager.cpp build: reduce usage of constexpr 2019-04-22 15:41:27 +03:00
test_lpsolver.cpp Merge remote-tracking branch 'origin/3.4' into merge-3.4 2023-06-20 09:56:57 +03:00
test_main.cpp Merge pull request #11897 from Jakub-Golinowski:hpx_backend 2018-08-31 16:23:26 +03:00
test_mat.cpp Fix empty ND-array construction 2025-06-02 10:13:49 +02:00
test_math.cpp Merge pull request #27347 from MaximSmolskiy:improve-solveCubic-accuracy 2025-05-24 09:56:48 +03:00
test_misc.cpp Merge pull request #26022 from Kumataro:fix26016 2024-08-23 12:35:13 +03:00
test_opencl.cpp UMat usageFlags fixes opencv/opencv#19807 2021-06-03 16:33:03 +02:00
test_operations.cpp Merge pull request #27184 from CodeLinaro:gemm_fastcv_hal 2025-04-25 11:07:26 +03:00
test_precomp.hpp Merge pull request #23736 from seanm:c++11-simplifications 2024-01-19 16:53:08 +03:00
test_ptr.cpp 3.4: backported changes from 'master' branch 2019-08-14 16:36:08 +03:00
test_quaternion.cpp Merge pull request #19026 from chargerKong:dualquat 2021-02-17 17:05:08 +00:00
test_rand.cpp Merge pull request #26259 from Kumataro:fix26258 2024-10-08 15:55:00 +03:00
test_rotatedrect.cpp ts: refactor OpenCV tests 2018-02-03 19:39:47 +00:00
test_umat.cpp Merge pull request #27408 from KAVYANSHTYAGI:Umat-vector-contructor 2025-06-09 16:02:38 +03:00
test_utils_tls.impl.hpp Merge pull request #23736 from seanm:c++11-simplifications 2024-01-19 16:53:08 +03:00
test_utils.cpp replace lena.jpg in find-existing-file tests 2024-05-25 08:53:33 +01:00