opencv: Carotene (ARM HAL) uses wrong rounding in some places
System Information
- OpenCV version: 4.8.0
- Operating System: macOS 13.3.1 (ARM64) / Ubuntu 20.04.4 (x86_64)
- Compiler: Apple clang version 14.0.3 / g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Detailed description
Even this (1+0)/2
gives different result on macOS and Linux:
cv::Mat A = cv::Mat::ones(3, 3, CV_8UC1);
cv::Mat B = cv::Mat::zeros(3, 3, CV_8UC1);
cv::Mat mean = (A + B) / 2;
std::cout << "A = \n" << A << std::endl;
std::cout << "B = \n" << B << std::endl;
std::cout << "(A+B)/2 = \n" << mean << std::endl;
Steps to reproduce
Write this code:
cv::Mat A = cv::Mat::ones(3, 3, CV_8UC1);
cv::Mat B = cv::Mat::zeros(3, 3, CV_8UC1);
cv::Mat mean = (A + B) / 2;
std::cout << "A = \n" << A << std::endl;
std::cout << "B = \n" << B << std::endl;
std::cout << "(A+B)/2 = \n" << mean << std::endl;
On macOS:
A =
[ 1, 1, 1;
1, 1, 1;
1, 1, 1]
B =
[ 0, 0, 0;
0, 0, 0;
0, 0, 0]
(A+B)/2 =
[ 1, 1, 1;
1, 1, 1;
1, 1, 0]
On Linux:
A =
[ 1, 1, 1;
1, 1, 1;
1, 1, 1]
B =
[ 0, 0, 0;
0, 0, 0;
0, 0, 0]
(A+B)/2 =
[ 0, 0, 0;
0, 0, 0;
0, 0, 0]
Issue submission checklist
- I report the issue, it’s not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 15 (14 by maintainers)
Correct result is “all zeros”. Looks like these is some issue with ARM optimizations on OSX.
Verification:
cmake <...> -DCMAKE_BUILD_TYPE=Debug -DCV_DISABLE_OPTIMIZATION=ON
Thank you for comment. This is only trial, however I think this fix will slow down processing. I’ll continue to investigate …
armv7 is still more than alive. Its support is required.
This issue still exists after the newest fix #24215
The result on macOS is so weird, why it is all
1
s except the last one?