mirror of
https://github.com/opencv/opencv.git
synced 2026-10-28 08:35:30 +08:00
ce58bb1ee7814766609c7dadd24720a7390e40eb
core: accept both float->int saturation results in OCL ConvertToSaturate test - #30448 Fixes the `macOS-x64 / BuildAndTest` failure from #30386, which makes 5.x macOS-x64 CI red for every PR (e.g. #30302): ``` [ RUN ] OCL_MatrixOperation/ConvertToSaturate.Accuracy/16, where GetParam() = (CV_32F, CV_32S) test_matrix_operation.cpp:247: Failure cv::countNonZero(diff) Which is: 2 ``` INT_MAX isn't representable in float, so a saturated `CV_32F -> CV_32S` result can legitimately be either value: - x86 CPU (`v_round` / `cvRound`) clamps to `CV__FLT2INT_MAX_F` = 2147483520 before converting (since #30007). - OpenCL `convert_int_sat_rte` and NEON `vcvtnq_s32_f32` give INT_MAX = 2147483647. So on an x86 host the out-of-range inputs `3e9` and `1e20` differ by 127 between `Mat` and `UMat`. On Apple M1 both sides give INT_MAX, which is why it only shows up on macOS-x64. For this pair the test now clamps both results to 2147483520 before the exact comparison, i.e. it accepts any value in [2147483520, INT_MAX] as saturated. In-range values and all other depth pairs are still compared exactly. **Testing** (Apple M1 Pro, OpenCL on; native arm64 build and an x86_64 build run under Rosetta 2) `Mat::convertTo` vs `UMat::convertTo` for `CV_32F -> CV_32S`: | input | arm64 CPU | x86_64 CPU | OpenCL | |---|---|---|---| | 3e9 | 2147483647 | 2147483520 | 2147483647 | | 1e20 | 2147483647 | 2147483520 | 2147483647 | The x86_64 build reproduces the CI mismatch. With this change, on both builds: - `opencv_test_core --gtest_filter=*ConvertToSaturate*`: 135 passed. - `opencv_test_core --gtest_filter=OCL_*:*ConvertTo*:*convertTo*:*Core_ConvertScale*`: 7549 passed. ### 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
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/5.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on X
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Languages
C++
86.2%
Python
4%
C
2.8%
CMake
2.2%
Java
1.6%
Other
3.1%