mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
Fixed meanStdDev() implementation for the case input matrix has more than 4 channels
This commit is contained in:
parent
c331a214d0
commit
2f929376ec
@ -306,14 +306,14 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
|||||||
if( !mask )
|
if( !mask )
|
||||||
{
|
{
|
||||||
SumSqr_SIMD<T, ST, SQT> vop;
|
SumSqr_SIMD<T, ST, SQT> vop;
|
||||||
int i = vop(src0, mask, sum, sqsum, len, cn), k = cn % 4;
|
int x = vop(src0, mask, sum, sqsum, len, cn), k = cn % 4;
|
||||||
src += i * cn;
|
src = src0 + x * cn;
|
||||||
|
|
||||||
if( k == 1 )
|
if( k == 1 )
|
||||||
{
|
{
|
||||||
ST s0 = sum[0];
|
ST s0 = sum[0];
|
||||||
SQT sq0 = sqsum[0];
|
SQT sq0 = sqsum[0];
|
||||||
for( ; i < len; i++, src += cn )
|
for(int i = x; i < len; i++, src += cn )
|
||||||
{
|
{
|
||||||
T v = src[0];
|
T v = src[0];
|
||||||
s0 += v; sq0 += (SQT)v*v;
|
s0 += v; sq0 += (SQT)v*v;
|
||||||
@ -325,7 +325,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
|||||||
{
|
{
|
||||||
ST s0 = sum[0], s1 = sum[1];
|
ST s0 = sum[0], s1 = sum[1];
|
||||||
SQT sq0 = sqsum[0], sq1 = sqsum[1];
|
SQT sq0 = sqsum[0], sq1 = sqsum[1];
|
||||||
for( ; i < len; i++, src += cn )
|
for(int i = x; i < len; i++, src += cn )
|
||||||
{
|
{
|
||||||
T v0 = src[0], v1 = src[1];
|
T v0 = src[0], v1 = src[1];
|
||||||
s0 += v0; sq0 += (SQT)v0*v0;
|
s0 += v0; sq0 += (SQT)v0*v0;
|
||||||
@ -338,7 +338,7 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
|||||||
{
|
{
|
||||||
ST s0 = sum[0], s1 = sum[1], s2 = sum[2];
|
ST s0 = sum[0], s1 = sum[1], s2 = sum[2];
|
||||||
SQT sq0 = sqsum[0], sq1 = sqsum[1], sq2 = sqsum[2];
|
SQT sq0 = sqsum[0], sq1 = sqsum[1], sq2 = sqsum[2];
|
||||||
for( ; i < len; i++, src += cn )
|
for(int i = x; i < len; i++, src += cn )
|
||||||
{
|
{
|
||||||
T v0 = src[0], v1 = src[1], v2 = src[2];
|
T v0 = src[0], v1 = src[1], v2 = src[2];
|
||||||
s0 += v0; sq0 += (SQT)v0*v0;
|
s0 += v0; sq0 += (SQT)v0*v0;
|
||||||
@ -351,10 +351,10 @@ static int sumsqr_(const T* src0, const uchar* mask, ST* sum, SQT* sqsum, int le
|
|||||||
|
|
||||||
for( ; k < cn; k += 4 )
|
for( ; k < cn; k += 4 )
|
||||||
{
|
{
|
||||||
src = src0 + k;
|
src = src0 + x * cn + k;
|
||||||
ST s0 = sum[k], s1 = sum[k+1], s2 = sum[k+2], s3 = sum[k+3];
|
ST s0 = sum[k], s1 = sum[k+1], s2 = sum[k+2], s3 = sum[k+3];
|
||||||
SQT sq0 = sqsum[k], sq1 = sqsum[k+1], sq2 = sqsum[k+2], sq3 = sqsum[k+3];
|
SQT sq0 = sqsum[k], sq1 = sqsum[k+1], sq2 = sqsum[k+2], sq3 = sqsum[k+3];
|
||||||
for( ; i < len; i++, src += cn )
|
for(int i = x; i < len; i++, src += cn )
|
||||||
{
|
{
|
||||||
T v0, v1;
|
T v0, v1;
|
||||||
v0 = src[0], v1 = src[1];
|
v0 = src[0], v1 = src[1];
|
||||||
|
@ -2184,4 +2184,21 @@ TEST(Core_ConvertTo, regression_12121)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Core_MeanStdDev, regression_multichannel)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
uchar buf[] = { 1, 2, 3, 4, 5, 6, 7, 8,
|
||||||
|
3, 4, 5, 6, 7, 8, 9, 10 };
|
||||||
|
double ref_buf[] = { 2., 3., 4., 5., 6., 7., 8., 9.,
|
||||||
|
1., 1., 1., 1., 1., 1., 1., 1. };
|
||||||
|
Mat src(1, 2, CV_MAKETYPE(CV_8U, 8), buf);
|
||||||
|
Mat ref_m(8, 1, CV_64FC1, ref_buf);
|
||||||
|
Mat ref_sd(8, 1, CV_64FC1, ref_buf + 8);
|
||||||
|
Mat dst_m, dst_sd;
|
||||||
|
meanStdDev(src, dst_m, dst_sd);
|
||||||
|
EXPECT_EQ(0, cv::norm(dst_m, ref_m, NORM_L1));
|
||||||
|
EXPECT_EQ(0, cv::norm(dst_sd, ref_sd, NORM_L1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user