mirror of
https://github.com/opencv/opencv.git
synced 2026-10-28 16:46:46 +08:00
fix(python): handle non-native NumPy byte order 🤖🤖🤖 - #30369 Python bindings can read non-native-endian NumPy inputs as native bytes, producing incorrect values or NaN. Mark swapped arrays for the existing cast path before constructing `Mat`; this also rejects incompatible output/in-place destinations before writes. Closes #30368. Targets 4.x so the common bridge fix can be merged into 5.x. Validation on macOS ARM64, Python 3.11.11, NumPy 2.4.6: - Built current 4.x and 5.x. Three regression tests cover 20 dtype/layout/output cases; 18 fail before and all pass after. Read-only inputs and rejected destinations remain unchanged. - 21 native-input timing cells on 4.x, 101 alternating pairs: fixed/baseline median time 0.957–1.005×, identical results. The 5.x check also stayed within 0.971–1.004×. - Draft: Linux/hosted CI validation remains pending. ### Pull Request Readiness Checklist - [x] I agree to contribute to the project under Apache 2 License. - [x] The patch is not based on GPL or other incompatible code. - [x] The PR targets the appropriate branch. - [x] The original bug report is linked. - [x] Regression tests and native-input performance checks are included; no external test data is needed. - [x] No public API, feature documentation or sample changes are needed.