Repository: opencv
Issue: meanStdDev bug while RUN_TESTS for opencv_test_core
Labels: bug

### System Information

OpenCV version: 4.6.0 with contrib module
Operating System / Platform: Windows 10 educational
Compiler & compiler version: Visual Studio 2022


### Detailed description

When I run the RUN_TESTS for the compiled opencv 4.6 (with contrib module 4.6), and without the "with_IPP" and "with_OPENCL" options, the RUN_TESTS will give me such issue:


> 
> [----------] 1 test from Core_MeanStdDev/ElemWiseTest
> [ RUN      ] Core_MeanStdDev/ElemWiseTest.accuracy/0, where GetParam() = 16-byte object <10-63 C9-AB 98-01 00-00 30-46 E1-AB 98-01 00-00>
> 
> E:\MyDrivers\api\opencv-4.6.0\sources\modules\core\test\test_arithm.cpp(1505): error: too big relative difference (0.31746958239660777 > 0.12431653146558173) between 64fC4 2-dim (1 x 2) 'dst0' and 'dst' at [0, 7].
> - dst0:
> 84.96203571109626, 292.2867051351412, 117.2226766848602, 145.7930433566753, 604.0160556371524, 573.5476616810923, 566.4748429192583, *427.6311850711165*.
> - dst:
> 84.96203571109626, 292.2867051351412, 117.2226766848602, 145.7930433566753, 604.0160556371524, 573.5476616810923, 598.5923379483519, *627.0030516093238*.
> 
> 
> src[0] ~ 64fC4 2-dim (1 x 18)
> testCase #343

Actually, I tried to print the tested src Mat and perform the calculation myself, the dst0 is correct (for the 3rd column with conv=566.47), while the dst is wrong. The src Mat (4 channels) is as follows:
> -73.62713441    280.4789855 -334.6340674    -219.7272904
> -607.7548047    -755.2156259    -997.4985087    268.3496785
> 149.2775288 576.5006519 498.2970279 267.1693062
> -874.7861883    396.2149921 505.3383681 -8.805473687
> 165.0991975 -987.3847146    657.0005484 538.2661919
> 753.5044804 685.4099242 425.0569732 -0.026177985
> -772.25543  -21.399704  -104.2522104    391.1741008
> -225.6105867    852.20889   479.8527143 480.3463748
> 845.4971929 705.4109547 360.1990013 -283.3870267
> 941.9562699 552.0246371 39.55008381 33.0637321
> -184.7803476    362.3189292 -644.0262049    924.8139461
> 647.9731311 897.8831332 579.705476  266.3566914
> 815.6293445 561.8476381 986.5666662 399.2300557
> 313.350129  676.4778877 854.5349978 -585.6877577
> 615.7872755 -161.5565781    -263.7773417    85.10474015
> 342.8826109 -720.2919446    31.15492855 926.3618211
> -886.1881474    968.2679416 -950.228709 -609.7302309
> -436.6378786    391.9646944 -12.83156304    -248.5979009

Also I found that in modules\core\src\mean.dispatch.cpp, after Line 593, when I print out sq as 

>     double scale = nz0 ? 1./nz0 : 0.;
>     std::cout << sq[0] << ' ' << sq[1] << ' ' << sq[2] << ' ' << sq[3] << std::endl;
> 
>     for( k = 0; k < cn; k++ )
>     {
>         s[k] *= scale;
>         sq[k] = std::sqrt(std::max(sq[k]*scale - s[k]*s[k], 0.));
>     }
I got: 6.69697e+06 7.45899e+06 6.69697e+06 7.45899e+06
The 1st and 2nd numbers are correct, but the 3rd and 4th number of sq are just the same as the 1st and 2nd. That is not possible for the given randomly generated src Mat.

I guess the problem comes from the SumSqrFunc? Or why should the sq results wrong?

### Update:
More information: the tested src is 64FC4, I don't know whether it is the key point.
However, I found a solution:
Interestingly, I found that the problem lies here (core\src\mean_simd.hpp):
![198824972-822c5bb9-c4be-440f-9386-d03bd49bb2b6](https://user-images.githubusercontent.com/16728292/198825279-f9af2bb9-024b-4248-b722-0038ad437f64.png)
When I add v2 and v3 variables here, everything works fine:
![198824995-836703b5-f9f7-4d20-a50f-39475843e043](https://user-images.githubusercontent.com/16728292/198825285-8cf44890-aff1-40fe-bce4-247fbab6fa88.png)

I think there is something wrong with the optimization (IPP? OVX? I have shut with_IPP down already...) of this function, and somehow the v0, v1 values in core\src\mean_simd.hpp line 227 have not been changed, as I mentioned before, the sqsum values of 2 and 3 are the same as 0 and 1 in such case, and when I change v0 v1 to v2 v3 (new variables), everything is OK.

### Steps to reproduce

Illustrated above.

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [x] I updated to the latest OpenCV version and the issue is still there
- [x] There is reproducer code and related data files (videos, images, onnx, etc)