Commit Graph

62 Commits

Author SHA1 Message Date
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
Suleyman TURKMEN
0e6a2c0491 fix legacy constants 2022-01-03 15:08:10 +03:00
Dale Phurrough
9bda96d39e
add test case 2021-08-25 14:32:40 +02:00
Alexander Alekhin
b3755e617c ocl: silence warning in case of async cleanup
- OpenCL kernel cleanup processing is asynchronous and can be called even after forced clFinish()
- buffers are released later in asynchronous mode
- silence these false positive cases for asynchronous cleanup
2020-08-20 19:33:37 +00:00
clunietp
2185bce4b7 Fix 13577 2019-11-18 07:41:34 -05:00
luz.paz
5718d09e39 Misc. modules/ typos
Found via `codespell`
2018-02-12 07:09:43 -05:00
Alexander Alekhin
4a297a2443 ts: refactor OpenCV tests
- removed tr1 usage (dropped in C++17)
- moved includes of vector/map/iostream/limits into ts.hpp
- require opencv_test + anonymous namespace (added compile check)
- fixed norm() usage (must be from cvtest::norm for checks) and other conflict functions
- added missing license headers
2018-02-03 19:39:47 +00:00
Dmitry Kurtaev
8b094755fa Fix https://github.com/opencv/opencv/issues/8693 2017-09-05 23:33:18 +03:00
Vladislav Sovrasov
14451f3f06 core: fix adjustROI behavior on indexes overflow 2017-02-22 14:05:51 +03:00
Alexander Alekhin
f50f34016e test: fix test crash (exception in destructor) 2016-09-22 15:18:32 +03:00
Alexander Alekhin
f48cda2f95 test: initialize test data in test_umat.cpp (6102) 2016-02-12 13:15:15 +03:00
Alexander Alekhin
96f5a930f4 test: regression 5991 2016-01-26 14:11:53 +03:00
Vadim Pisarevsky
3942b1f362 Merge pull request #5340 from alalek:ocl_off 2015-11-10 16:53:36 +00:00
Maksim Shabunin
31e0d90da6 Enable temp objects destruction test for VS versions less than 2015 2015-10-22 12:44:03 +03:00
Maksim Shabunin
6e9d0d9a0c Visual Studio 2015 warning and test fixes 2015-10-20 12:48:37 +03:00
Alexander Alekhin
bf42b9603b fix "unreachable code" warning 2015-09-14 13:11:12 +03:00
Alexander Alekhin
7213e5f68a ocl: correct disabling of OpenCL code 2015-09-13 20:28:23 +03:00
Alexander Alekhin
ad70ab404c ocl: workaround for getUMat() 2015-09-09 18:56:14 +03:00
Andrey Pavlenko
cea2dafa0f man/unmap, preventing getMat/getUMat from temp object, fix thread-unsafe code in UMat::getMat() 2015-09-09 18:05:29 +03:00
Alexander Alekhin
8694ba0978 update custom_ptr test 2015-09-03 10:46:38 +03:00
Vadim Pisarevsky
a78da45fec Merge pull request #5242 from apavlenko:fix_releasing_temp_umat 2015-08-27 14:29:52 +00:00
Andrey Pavlenko
4aefb9f2fc making the test deepper 2015-08-26 13:38:26 +03:00
Andrey Pavlenko
3656a1aa66 fixing 'map_unmap_counting' 2015-08-25 17:25:03 +03:00
Vadim Pisarevsky
bd8bac27d5 Merge pull request #4212 from ludv1x:master 2015-08-24 14:20:54 +00:00
Vitaliy Lyudvichenko
85cc11e3b2 Changed behaviour of Mat/UMat::reshape() to accept n-dim shapes 2015-08-21 19:26:29 +03:00
Alexander Alekhin
68f8d1cef0 Merge pull request #5164 from vladimir-dudnik:test-umat-copyTo-issue 2015-08-13 14:59:07 +00:00
Vladimir Dudnik
131d7c394e enabled test UMat copyTo. Now it will detect FAIL on Intel platform for ROI (issue with clEnqueueCopyBufferRect) 2015-08-11 14:19:14 +03:00
Alexander Alekhin
09b9b0fb9e Merge pull request #5135 from alalek:issue_4468 2015-08-10 14:46:31 +00:00
Alexander Alekhin
3316e58314 more test loops (and disable tests - tests pass but require a lot of time) 2015-08-10 14:44:28 +03:00
Alexander Alekhin
8293ed7f9b add tests from issue 4468 (#5062) 2015-08-06 13:50:13 +03:00
Alexander Alekhin
21467d817b tapi: add test from issue 4380 (#5010) 2015-08-05 16:08:48 +03:00
Alexander Alekhin
1704aea6a0 tapi: enable some disabled tests 2015-07-30 19:21:24 +03:00
Alexander Alekhin
9bcccb028b fixes 2015-07-28 11:49:46 +03:00
Alexander Alekhin
cd5c70691a ocl: add map tests 2015-07-28 11:49:46 +03:00
Alexander Alekhin
b36f565d13 fix OpenCV code (bug 4006: #4862) 2015-07-28 11:49:41 +03:00
Vladimir Dudnik
ed7907e46c add test for bug 4006: #4862 2015-07-28 11:49:02 +03:00
Vadim Pisarevsky
7c8789dc12 fixed my_umat(roi).clone() test by disabling poorly aligned ROI's. Real fix of the problem will require a separate branch in UMat::copyTo(). 2014-11-07 14:49:48 +03:00
Alexander Karsakov
00221e96fd Fixed issue: Mat::copyTo(UMat) if device copy is obsolete. Added test. 2014-08-07 13:16:02 +04:00
Ilya Lavrenov
aa5326c231 cv::norm -> cvtest::norm in tests
Conflicts:

	modules/core/src/stat.cpp
2014-04-08 14:49:20 +04:00
Alexander Alekhin
3488fdcb43 disable failed tests 2014-03-26 19:29:59 +04:00
Alexander Alekhin
569e1346f2 UMat: issue in OpenCLAllocator::unmap() 2014-03-26 19:29:41 +04:00
Alexander Alekhin
6bd7a444bc UMat map-unmap synchronization test 2014-03-25 16:19:52 +04:00
Ilya Lavrenov
f404315368 test for clEnqueueReadBufferRect 2014-03-06 12:11:46 +04:00
Ilya Lavrenov
9b627a5e9f disabled 'reshape', 'copyTo' test 2014-02-15 20:17:42 +04:00
Ilya Lavrenov
7ce2c3574a restored lost in PR #1735 umat tests 2014-02-15 16:09:55 +04:00
Ilya Lavrenov
4f36bc29d9 cleaned-up UMat tests 2014-02-15 15:51:52 +04:00
Konstantin Matskevich
5f76072c62 update 2014-02-13 13:29:53 +04:00
Konstantin Matskevich
a0a3b8b56d Some tests for UMat 2014-02-13 09:59:05 +04:00
Alexander Alekhin
485635310c core/ocl: OpenCLBufferPool 2014-02-04 16:48:35 +04:00
Konstantin Matskevich
ffeb223150 test for failure 2014-02-03 14:34:02 +04:00