mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 21:23:31 +08:00
fix meanStdDev overflow for large images
This commit is contained in:
parent
43cebe52eb
commit
987ba6504b
@ -592,7 +592,8 @@ void meanStdDev(InputArray _src, OutputArray _mean, OutputArray _sdv, InputArray
|
|||||||
uchar* ptrs[2] = {};
|
uchar* ptrs[2] = {};
|
||||||
NAryMatIterator it(arrays, ptrs);
|
NAryMatIterator it(arrays, ptrs);
|
||||||
int total = (int)it.size, blockSize = total, intSumBlockSize = 0;
|
int total = (int)it.size, blockSize = total, intSumBlockSize = 0;
|
||||||
int j, count = 0, nz0 = 0;
|
int j;
|
||||||
|
int64_t count = 0, nz0 = 0;
|
||||||
AutoBuffer<double> _buf(cn*4);
|
AutoBuffer<double> _buf(cn*4);
|
||||||
double *s = (double*)_buf.data(), *sq = s + cn;
|
double *s = (double*)_buf.data(), *sq = s + cn;
|
||||||
int *sbuf = (int*)s, *sqbuf = (int*)sq;
|
int *sbuf = (int*)s, *sqbuf = (int*)sq;
|
||||||
|
@ -2814,6 +2814,19 @@ TEST(Core_MeanStdDev, regression_multichannel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Related issue : https://github.com/opencv/opencv/issues/26861
|
||||||
|
TEST(Core_MeanStdDevTest, LargeImage)
|
||||||
|
{
|
||||||
|
applyTestTag(CV_TEST_TAG_VERYLONG);
|
||||||
|
applyTestTag(CV_TEST_TAG_MEMORY_14GB);
|
||||||
|
// (1<<16) * ((1<<15)+10) = ~2.147 billion
|
||||||
|
cv::Mat largeImage = cv::Mat::ones((1 << 16), ((1 << 15) + 10), CV_8U);
|
||||||
|
cv::Scalar mean, stddev;
|
||||||
|
cv::meanStdDev(largeImage, mean, stddev);
|
||||||
|
EXPECT_NEAR(mean[0], 1.0, 1e-5);
|
||||||
|
EXPECT_NEAR(stddev[0], 0.0, 1e-5);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T> static inline
|
template <typename T> static inline
|
||||||
void testDivideInitData(Mat& src1, Mat& src2)
|
void testDivideInitData(Mat& src1, Mat& src2)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user