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
test_conjugate_gradient.cpp
test_countnonzero.cpp Add missing std namespace qualifiers 2023-09-06 13:46:39 +03:00
test_cuda.cpp
test_downhill_simplex.cpp
test_ds.cpp
test_dxt.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
test_eigen.cpp
test_hal_core.cpp fix exp, log | enable ui for log | strengthen test 2025-03-07 17:11:26 +00:00
test_hasnonzero.cpp
test_intrin128.simd.hpp
test_intrin256.simd.hpp
test_intrin512.simd.hpp
test_intrin_emulator.cpp
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
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
test_logtagmanager.cpp
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
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
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
test_quaternion.cpp
test_rand.cpp Merge pull request #26259 from Kumataro:fix26258 2024-10-08 15:55:00 +03:00
test_rotatedrect.cpp
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