mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 13:16:32 -06:00
core: support CV_Bool input in mean and meanStdDev - #30999 Fixes #30998 ### Problem `cv::mean` and `cv::meanStdDev` fail with `func != 0` on a `CV_Bool` source, because there is no `CV_Bool` sum kernel. `cv::sum` and `cv::norm` already handle `CV_Bool`. ### Fix For a `CV_Bool` source, compute the result from `countNonZero` and `total()` instead of the sum kernels: mean = nz/n, and stddev = sqrt(p*(1-p)) with p = nz/n. A mask, or more than one channel, reports `StsNotImplemented`. ### Tests Added `Core_MeanStdDev.bool_input`: a 1-channel `CV_Bool` source (including a raw `255` byte) must give mean 0.5 and stddev 0.5, and both functions must throw when a mask is given. It fails on the current code with the assert and passes with the fix. The full `opencv_test_core` run passes. ### 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