mirror of
https://github.com/opencv/opencv.git
synced 2026-01-12 00:06:29 +08:00
js: restore deep copy behavior for Mat.clone() #28216 ### Problem In OpenCV.js, `cv.Mat.clone()` may resolve to Embind `ClassHandle.clone()` (handle/shallow clone) instead of OpenCV deep copy. ### Changes - modules/js/src/helpers.js: override `cv.Mat.prototype.clone` -> `mat_clone` after runtime init - modules/js/test/test_mat.js: update/extend tests to validate deep copy semantics of `clone()` Fixes #27572 Related: PR #26643 (js_clone_fix), PR #27985 (documentation update) ### Verification - Built OpenCV.js with Emscripten 2.0.10 - QUnit: bin/tests.html - CoreMat: test_mat_creation (0 failures) <img width="745" height="362" alt="clone_fix" src="https://github.com/user-attachments/assets/16399abf-b94c-4591-b4aa-6e0fbd6cf23b" /> ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake