mirror of
https://github.com/opencv/opencv.git
synced 2025-06-25 05:32:14 +08:00
![]() 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 |
||
---|---|---|
.. | ||
3rdparty/SoftFloat | ||
cmake/parallel | ||
doc | ||
include/opencv2 | ||
misc | ||
perf | ||
src | ||
test | ||
CMakeLists.txt |