js: restore deep copy behavior for Mat.clone()#28216
Conversation
Emscripten 3.1.71+ introduced ClassHandle.clone() which performs a shallow copy. This shadowed the original OpenCV clone() method which was intended for deep copying. This patch: 1. Hooks into onRuntimeInitialized in helpers.js 2. Overrides cv.Mat.prototype.clone to point to mat_clone (deep copy) 3. Updates JS tests to use clone() to verify the fix
|
I think it makes sense. Users will no more about OpenCV that emscripten and will therefore expect clone to behave like in C++. LGTM |
|
Thanks for the review! I've removed the extra blank line at the end of helpers.js |
|
@asmorkalov Hi, the CI seems to have failed due to network issues. Could you please help re-run the failed jobs? I'm hoping to include this in a report due this Tuesday. Thanks for your help!! |
|
@asmorkalov Apologies for the extra notification. I just wanted to flag that the CI re-run unfortunately hit the same Windows infrastructure error ( Since this is blocking the merge and my reporting deadline is tomorrow (Tuesday), I wanted to bring this to your attention one last time. I hope it's okay to ask for a merge based on the existing approval, given the CI instability. Thanks again for your patience and help! |
Problem
In OpenCV.js,
cv.Mat.clone()may resolve to EmbindClassHandle.clone()(handle/shallow clone) instead of OpenCV deep copy.Changes
cv.Mat.prototype.clone->mat_cloneafter runtime initclone()Fixes #27572
Related: PR #26643 (js_clone_fix), PR #27985 (documentation update)
Verification
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.